bob

SQL query builder and ORM/Factory generator for Go with support for PostgreSQL, MySQL and SQLite

MIT License

Stars
760
Committers
22
bob - v0.20.0

Published by stephenafamo over 1 year ago

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.19.1...v0.20.0

Added

  • Add the PreloadWhere preload mod to filter what relation should be preloaded.
  • ViewQuery now embeds bob.BaseQuery giving it additional methods like Apply and Build
  • Add plugin support. Currently 3 plugin hooks are provided. PlugState, PlugDBInfo and PlugTemplateData.

Changed

  • Make View.Name() return a dialect-specific expression
  • Improve Debug helpers.
    • Debug writes query output to stdout
    • DebugToWriter writes the query output to any io.Writer with a fallback to stdout.
    • DebugToPrinter prints the query with a given bob.DebugPrinter. Also falls back to stdout.
  • Rename OnlyColumns to PreloadOnly and ExceptColumns to PreloadExcept to be more consistent with the newly added PreloadWhere.
  • JoinChain.On now takes Expressions instead of any.
  • JoinChain.Using now takes strings instead of any.
  • Export gen.TemplateData

Removed

  • Remove ILIKE operator from MySQL since it is not supported.
  • Removed Destination() method in driver interface.
  • Removed PackageName() method in driver interface.

Fixed

  • Account for possible clashes between column and relationship alias
  • Make Preload mods work the same way as other query mods
  • Avoid overwriting manually flipped relationships.
  • Account for potentially null relationship in Load methods
bob - v0.19.1

Published by stephenafamo over 1 year ago

  • Fix On method for JoinChain in mysql and sqlite

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.19.0...v0.19.1

bob - v0.19.0

Published by stephenafamo over 1 year ago

Added

  • Add LIKE and ILIKE operators
  • Print generated files
  • Add no_reverse option for user-configured relationships

Changed

  • Move common parts of loading to shared internal package

Fixed

  • Fix generated joins for multi-sided relationships

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.18.2...v0.19.0

bob - v0.18.2

Published by stephenafamo over 1 year ago

  • Account for relationships with tables that do not have a primary key in models and factories
  • Properly extract preloaders nested in mods.QueryMods
  • Fix bug in preloading with multiple sides
  • Fix issue with multi-sided relationships that include views

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.18.1...v0.18.2

bob - v0.18.1

Published by stephenafamo over 1 year ago

  • Make self-referencing foreign keys work
  • Tweak factory types to make collisions even less likely

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.18.0...v0.18.1

bob - v0.18.0

Published by stephenafamo over 1 year ago

Breaking Changes in v0.18.0

Comparison methods now require an expression (bob.Expression)

The primary breaking change is that several builder methods now require a bob.Expression instead of any.
While this makes building some simple queries more verbose, it makes it harder to make some errors.

As an example, consider the following query

// SELECT * FROM users WHERE id = 1
psql.Select(
  sm.From("users"),
  sm.Where(psql.X("id").EQ(1)),
)

This feels like the natural way to build this query, however there are some subtle potential issues:

  1. 1 should probably be passed as an argument. In a real world application, this could lead to an SQL injection.

    // SELECT * FROM users WHERE id = $1
    psql.Select(
      sm.From("users"),
      sm.Where(psql.X("id").EQ(psql.Arg(1))),
    )
    
  2. This query will throw an error if we use a string

    // !!!!INVALID QUERY!!!!
    // SELECT * FROM users WHERE name = Stephen 
    psql.Select(
      sm.From("users"),
      sm.Where(psql.X("name").EQ("Stephen")),
    )
    

The initial reason why these took any was to make Bob easy to adopt. However, after using this in practice, it is likely that the user always wants to do something to make it an expression.

  1. If it is a table or column name, it should probably be quoted with psql.Quote
  2. If it is an argument, it should be passed with psql.Arg

No more X builder

The X builder, while convenient doesn't quite fit in anywhere. Most queries will be started with a quote, and can then be fluently chained with other expressions.

In the interest of keeping the surface area of this pacakge small, I've decided to remove it until there is a concrete need.

No more P builder method

The P builder method was for adding parentheses to a single expression. However, this overlaps with the Group method with adds parentheses around a list of expressions separated with a comma.

Since using the Group method with a single expression does the same thing as the P method, the P method now feels redundant.

bob - v0.17.3

Published by stephenafamo over 1 year ago

  • Fix bug with args in table updates
  • Fix some typos in documentation (thanks @leonardtan13)
bob - v0.17.2

Published by stephenafamo over 1 year ago

  • Fix a bug when multiple multi-column foreign keys exist
  • Multiple internal changes to the generator to make it easier to write a custom entrypoint
  • More robust testing of code generation
  • json, yaml and toml struct tags are no longer autogenerated but can still be added though configuration
bob - v0.17.1

Published by stephenafamo over 1 year ago

Fix an issue in v0.17.0 which causes errors when generating sqlite models

bob - v0.17.0

Published by stephenafamo over 1 year ago

Easy Joins!

Now, Bob will generate join mods for model relationships

models.SelectJoin(ctx).Users.InnerJoin.Posts

Fixes

  • Fixed an issue with ON DUPLICATE KEY UPDATE (#14)
bob - v0.16.0

Published by stephenafamo over 1 year ago

  • Add a code generation driver for Atlas
  • Change how the um.Set update mod works to allow more query building
  • Add JOIN mods for MySQL update queries
  • Fix upserts in all 3 dialects to ignore the update columns when generating the insert column set
  • Return early in InsertMany/UpsertMany/UpdateMany/DeleteMany if 0 rows to act on
  • Report error if non-default codegen config file is misssing