Skip to content

v0.27.0

Compare
Choose a tag to compare
@stephenafamo stephenafamo released this 05 Jun 00:28
· 92 commits to main since this release

Added

  • Add PreloadAs PreloadOption to override the join alias when preloading a relationship with a left join. (thanks @daddz)

  • Add AliasedAs() method to tableColumns and tableWhere types to use a custom alias.

  • Add AliasedAs() method to generated relationship join mods. This is avaible in two places:

    • one to change the alias of the table being queried

      models.SelectJoins.Jets.AliasedAs("j").InnerJoin.Pilots(ctx)
    • and the other to change the alias of the relationship.

      models.SelectJoins.Jets.InnerJoin.Pilots(ctx).AliasedAs("p")
  • Add fm mods to all supported dialects (psql, mysql and sqlite). These are mods for functions and are used to modify the function call. For example:

    // import "github.com/stephenafamo/bob/dialect/psql/fm"
    psql.F( "count", "*",)(fm.Filter(psql.Quote("status").EQ(psql.S("done"))))
  • Add MustCreate, MustCreateMany, CreateOrFail and CreateManyOrFail methods to generated factory Templates

Changed

  • Change the function call point for generated relationship join mods. This reduces the amount of allocations and only does the work for the relationship being used.

    // Before
    models.SelectJoins(ctx).Jets.InnerJoin.Pilots
    // After
    models.SelectJoins.Jets.InnerJoin.Pilots(ctx)
  • Changed the Count() function on Views to clone the query instead of changing the existing one. This makes queries reusable and the Count() function to behave as one would expect.

    // This now works as expected
    query := models.Jets.Query(ctx, db, /** list of various mods **/)
    count, err := query.Count()
    items, err := query.All()
  • Changed how functions are modified. Instead of chained methods, the F() starter now returns a function which can be called with mods:

    // Before
    psql.F( "count", "*",).FilterWhere(psql.Quote("status").EQ(psql.S("done"))),
    // After
    // import "github.com/stephenafamo/bob/dialect/psql/fm"
    psql.F( "count", "*",)(fm.Filter(psql.Quote("status").EQ(psql.S("done")))),

    This makes it possible to support more queries.

  • Use netip.Addr instead of netip.Prefix for Postgres cidr type.

  • Use decimal.Decimal instead of string for Postgres money type.

  • Use net.HardwareAddr for Postgres macaddr8 type, in addition to the macaddr type.

  • Code generation now generates struct tags for the generated model Setters as well, if configured through the Tags configuration option. Previoulsy, only the model struct fields were tagged. (thanks @singhsays)

Removed

  • Remove TableWhere function from the generated code. It was not used by the rest of the generated code and offered no clear benefit.
  • Removed As starter. It takes an Expression and is not needed since the Expression has an As method which can be used directly.

Fixed

  • Fix a bug with types.Stringer[T] where the wrong value was returned in the Value() method.

New Contributors

Full Changelog: v0.26.1...v0.27.0