SQL query builder and ORM/Factory generator for Go with support for PostgreSQL, MySQL and SQLite
Count()
queries not removing the offset from the original query. (thanks @daddz)Full Changelog: https://github.com/stephenafamo/bob/compare/v0.27.0...v0.27.1
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
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)
TableWhere
function from the generated code. It was not used by the rest of the generated code and offered no clear benefit.As
starter. It takes an Expression
and is not needed since the Expression
has an As
method which can be used directly.types.Stringer[T]
where the wrong value was returned in the Value()
method.Full Changelog: https://github.com/stephenafamo/bob/compare/v0.26.1...v0.27.0
netip.Prefix
instead of netip.Addr
for postgres inet column type. This makes it possible to contain a subnet. By @stephenafamo in https://github.com/stephenafamo/bob/pull/217
Full Changelog: https://github.com/stephenafamo/bob/compare/v0.26.0...v0.26.1
bobgen-sql
a code generation driver for SQL schema files. Supports PostgreSQL and SQLite.compare_expr
and compare_expr_imports
to the types
configuration. This is used when comparing primary keys and in testing.never_required
to relationships configuration. This makes sure the factories does not require the relationship to be set. Useful if you're not using foreign keys. (thanks @jacobmolby)types
configuration.fmt.Stringer
, encoding.TextMarshaler
, encoding.TextUnmarshaler
, encoding.BinaryMarshaler
and encoding.BinaryUnmarshaler
interfaces.OVER ()
with an empty window definition in PostgreSQL. (thanks @relvacode)GROUP BY
to NULL
if there are no expressions to group by.Full Changelog: https://github.com/stephenafamo/bob/compare/v0.25.0...v0.26.0
github.com/jaswdr/faker
dependency from v1
to v2
Full Changelog: https://github.com/stephenafamo/bob/compare/v0.24.0...v0.25.0
gofumpt
replacements
configuration is now a string referring to the type defined in the types
configuration.Imports
from column definition.INTEGER
columns are now correctly generated as int32
not int
Full Changelog: https://github.com/stephenafamo/bob/compare/v0.23.2...v0.24.0
modify
for relationships with no primary keysql.ErrNoRows
when Insert/Upsert returns nothingFull Changelog: https://github.com/stephenafamo/bob/compare/v0.23.1...v0.23.2
Setter.Expressions()
in parenthesisFull Changelog: https://github.com/stephenafamo/bob/compare/v0.23.0...v0.23.1
bob.Cache()
which saves the built SQL and args to prevent rebuilding the same query multiple times.As()
starter to alias expressionsOP()
builder method for using custom operatorstable.InsertQ(ctx, db)
now includes the insert columns from the table model.um.SetCol()
which maintains the old behavior of um.Set()
.Expressions()
method for Setters to make it easier to use them in um.Set()
or im.Set()
.table
keyfrom_unique
, to_unique
, key_nullable
can no longer be configured. They are now inferred from the database.to_key
has been changed to modify
and should be set to from
, to
or ""
to indicate which side of the relationship to modify.
If left empty, Bob will try to guess which side to modify based on the presence of primary keys and unique columns.RelWhere.Value
is now RelWhere.SQLValue
um.Set()
to take a list of expressions.Insert()
to InsertMod()
to avoid confusion.JOIN USING
Full Changelog: https://github.com/stephenafamo/bob/compare/v0.22.0...v0.23.0
InsertQ
, UpdateQ
, and DeleteQ
methods to Table models to start INSERT, UPDATE and DELETE queries respectively.WhereOr
and WhereAnd
to make it easier to combine multiple generated where clausesExec()
method of view queries instead of sql.Result
Expression
instead of any
orm.Table
and orm.Setter
interfaces.TablesInfo
method and make sure we don't exclude entire table when targeting columns (thanks @jacobmolby)Full Changelog: https://github.com/stephenafamo/bob/compare/v0.21.1...v0.22.0