Skip to content

Releases: stephenafamo/bob

v0.20.2

05 Apr 10:39
Compare
Choose a tag to compare
  • Account for windows when calculating models module path

Full Changelog: v0.20.1...v0.20.2

v0.20.1

04 Apr 21:58
Compare
Choose a tag to compare
  • Update the generated code to use github.com/gofrs/uuid/v5
  • Fix bug where auto-increment columns were marked as generated in the SQLite driver

Full Changelog: v0.20.0...v0.20.1

v0.20.0

02 Apr 23:45
Compare
Choose a tag to compare

Full Changelog: 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

v0.19.1

21 Mar 09:12
Compare
Choose a tag to compare
  • Fix On method for JoinChain in mysql and sqlite

Full Changelog: v0.19.0...v0.19.1

v0.19.0

19 Mar 17:53
Compare
Choose a tag to compare

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: v0.18.2...v0.19.0

v0.18.2

18 Mar 14:58
Compare
Choose a tag to compare
  • 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: v0.18.1...v0.18.2

v0.18.1

16 Mar 20:48
Compare
Choose a tag to compare
  • Make self-referencing foreign keys work
  • Tweak factory types to make collisions even less likely

Full Changelog: v0.18.0...v0.18.1

v0.18.0

12 Mar 23:34
Compare
Choose a tag to compare

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.

v0.17.3

11 Mar 00:46
Compare
Choose a tag to compare
  • Fix bug with args in table updates
  • Fix some typos in documentation (thanks @leonardtan13)

v0.17.2

09 Mar 15:31
Compare
Choose a tag to compare
  • 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