Releases: stephenafamo/bob
v0.34.2
Fixed
- Fix bug with
bobgen-sql
parsing of string identifiers in certain cases.
Full Changelog: v0.34.1...v0.34.2
v0.34.1
Fixed
- Remove unnecessary limitation to place
FETCH WITH TIES
beforeOFFSET
. - Fix issue with verifying statements in
bobgen-psql
.
Full Changelog: v0.34.0...v0.34.1
v0.34.0
Added
- Added support to generate code for
UPDATE
, andDELETE
queries inbobgen-psql
.
Changed
- Changed to non-cgo version of postgres parser.
- Changed the
dir
configuration forbobgen-sql
topattern
and it now takes a glob pattern. This allows excluding certain files from being included (e.g..down.sql
files).
Full Changelog: v0.33.1...v0.34.0
v0.33.1
Changed
- When a query returns only one column, instead of returning a struct with one field, it will return the type of the column. This is to make it easier to use the generated code.
Fixed
- Fix panic when scanning returned rows from generated queries.
Full Changelog: v0.33.0...v0.33.1
v0.33.0
Added
- Added support to generate code for
INSERT
queries inbobgen-psql
. clause.Confict
now takesbob.Expression
, and the fields are now moved to aclause.ConflictClause
struct.
Changed
- Make grouped types in generated queries a type alias.
Removed
- Remove
models.InsertWhere
in generated code since it is not correct.
Fixed
- Fix issue with column query annotations in
bobgen-psql
. - Fix issue with parsing multiple queries in the same file in
bobgen-psql
. - Fix issue with correctly detecting the comment for the query annotation in
bobgen-psql
. - Use a transaction in generated query tests.
- Account for LEFT, RIGHT and FULL joins when determining the nullability of a column.
- Generate WHERE helpers for
ON CONFLICT
clauses.
Full Changelog: v0.32.0...v0.33.0
v0.32.0
Added
- Added templates for query generation.
- Added
clause.OrderBy.ClearOrderBy()
- Added
expr.ToArgs
andexpr.ToArgGroup
functions to convert slices of a type to args. - Add
queries
key tobobgen-sql
andbobgen-sqlite
configuration. This is used to specify what folder to search for queries in. - Implement the Postgres query parser for
SELECT
statements. - Implement the SQLite query parser for
SELECT
statements. - Add templates for query generation.
- Add
camelCase
template function. - Add types to the
orm
package to be used in generated queries.orm.ArgWithPosition
,orm.ModExpression
,orm.ModExecQuery
andorm.ModQuery
. - Add function
orm.ArgsToExpression
for use in the generated code. - Add
String()
method tobob.QueryType
Fixed
- Update
mvdan.cc/gofumpt
and give precedence to toolchain when calculating the Go version. (thanks @isgj) - Add custom comparison support when loading relationships.
- Fix issue with scanning Postgres inet type.
- Set
Arg
andArgGroup
toNULL
if there are no values. - Do not call
BeforeInsertHooks
in the insert mod of a view. - Fix issue with retrieving inserted rows with the MySQL driver.
- Add custom comparison for relationship loading. (thanks @kostaspt)
Changed
clause.With
now takesbob.Expression
instead ofclause.CTE
. This makes it easier to use in generated queries without reconstruction anCTE
.clause.OrderBy
now takesbob.Expression
instead ofclause.OrderDef
. This makes it easier to use in generated queries without reconstruction anOrderDef
.clause.Windows
now takesbob.Expression
instead ofclause.NamedWindow
. This makes it easier to use in generated queries without reconstruction the window.clause.For
renemaed toclause.Locks
and can now take multiple locks.clause.Fetch
now takesany
instead of an integer.- Several changes to the
drivers.Query
type as support is added for the new query parser. - Enum types can now be matched by
db_type
in bobgen-psql asschema.enum_type
. (thanks @abramlab)
Removed
- Removed
clause.OrderBy.SetOrderBy()
as it was only being used to clear the set order by clauses.
New Contributors
Full Changelog: v0.31.0...v0.32.0
v0.31.0
Added
- Added support for libSQL. (thanks @mbezhanov)
- Added support for declaring types inside the models package. (thanks @jacobmolby)
Changed
- Generates error constants with unique indexes instead of unique constraints. (thanks @tlietz)
Fixed
- Used
Equal
method for comparing decimals. (thanks @jalaziz) - Update
golang.org/x/mod
dependency to enable parsing of Go 1.23 modules. (thanks @m110)
New Contributors
- @tlietz made their first contribution in #360
- @jalaziz made their first contribution in #374
- @m110 made their first contribution in #358
Full Changelog: v0.30.0...v0.31.0
v0.30.0
Added
- Added a new field
QueryFolders
togen/drivers.DBInfo
for drivers to be able to include information about parsed queries. - Added
gen/QueriesTemplates
which in the future will contain base templates for generating code for parsed qureries. - Added a
QueryTemplate
field tobobgen_helpers.Templates
for drivers to include additional templates for queries. - Added a new reserved output key
queries
. This is handled specially for each query folder supplied by the driver. - Added new
wm
package to each dialect for mods that modifyWindow
clauses. - Added a new method
Alias
forView
struct, for each dialect. It returns the alias of the view. (thanks @Nitjsefni7)
Changed
- Updated error constant generation to employ specific error types for making error matching easier. (thanks @mbezhanov)
- Collation in
clause.OrderDef
is now a string not an expression and is always quoted - Calling
UpdateAll
,DeleteAll
andReloadAll
on an empty model slice now returns nil without running any queries. UNION
,INTERSECT
andEXCEPT
mods now append to the query instead of replacing it.- Generated files now end with
.bob.go
instead of.go
and are always cleaned up before generating new files. Singleton templates are now required to have a.bob.go.tpl
extension. - The expected structure for templates have been changed:
- Previously, singleton templates should be kept in a
singleton
folder. Now, any template not inside a folder is considered a singleton template. - Previoulsy, templates in the root folder are merged and run for each table. Now, this will happen to templates in the
table/
folder. - Previoulsy, the entire file tree and every subdirectory is walked to find templates. Now only templates in the root folder and the
table/
folder are considered.
- Previously, singleton templates should be kept in a
- Change
From
inclause.Window
toBasedOn
to avoid confusion withFromPreceding
andFromFollowing
. Also changeSetFrom
toSetBasedOn
. - Embed
clause.OrderBy
inclause.Window
to make it possible to reuseOrderBy
mods in window definitions. - Change the
Definition
field inclause.NamedWindow
fromany
toclause.Window
for extra type safety. sm.Window
now takes mods to modify the window clause.fm.Over
now takes mods to modify the window for the window function.
Deprecated
- Deprecated the
wipe
option to delete all files in the output folder. Files are now generated with a.bob.go
extension and are always cleaned up before generating new files.
Removed
- Remove redundatnt type parameters from
orm.ExecQuery
. - Remove unnecessary interface in
orm.Query
andorm.ExecQuery
. - Remove the redundant
clause.IWindow
interface. - Remove
dialect.WindowMod
anddialect.WindowMods
which use chainable methods to modifyWindow
clauses. This is now handled by thewm
package which used mods.
Fixed
- Fix random value generation for pq.Float64Array factory (thanks @felipeparaujo)
- Using the
UpdateMod()
andDeleteMod()
methods on an empty model slice now appendsWHERE primary_key IN NULL
which will return no results. Instead ofWHERE primary_key IN ()
which is a syntax error. - Ensure
net/netip
is imported for thepgtypes.Inet
random expression (thanks @plunkettscott) - Fix a data race when adding enum types.
- Fix missing schema in table alias in pkEQ and pkIN clauses (thanks @adatob).
New Contributors
- @felipeparaujo made their first contribution in #321
- @plunkettscott made their first contribution in #328
- @adatob made their first contribution in #327
- @Nitjsefni7 made their first contribution in #339
Full Changelog: v0.29.0...v0.30.0
v0.29.0
Added
- Added error constants for matching against both specific and generic unique constraint errors raised by the underlying database driver. (thanks @mbezhanov)
- Added support for regular expressions in the
only
andexcept
table filters. (thanks @mbezhanov) - Added
ContextualMods
which are similar to regular mods but take a context argument. They are applied whenever the query is built.
This makes it cleaner to do certain things, like populating the select columns of a model if none was explicitly added.
The previous way this was done was unreliable since usingq.MustBuild()
would not add the columns whilebob.MustBuild(q)
will add them correctly. modelSlice.UpdateMod()
andmodelSlice.DeleteMod()
are new methods that returns a mod for update and delete queries on a slice of models.
It addsWHERE pk IN (pk1, pk2, pk3, ...)
to the query, and also schedule running the hooks.- Added
bob.ToMods
which a slice of structs that implementbob.Mod[T]
to a Mod. This is useful since Go does not allow using a slice of structs as a slice of an interface the struct implements. - Added
bob.HookableQuery
interface. If a query implements this interface, the methodRunHooks(ctx, exec)
will be called before the query is executed. - Added
bob.HookableType
interface. If a type implements this interface, the methodAfterQueryHook(ctx, exec, bob.QueryType)
will be called after the query is executed.
This is howAfterSeleect/Insert/Update/DeleteHooks
hooks are now implemented. - Added
Type() QueryType
method tobob.Query
to get the type of query it is. Available constants areUnknown, Select, Insert, Update, Delete
. - Postgres and SQLite Update/Delete queries now refresh the models after the query is executed. This is enabled by the
RETURNING
clause, so it is not available in MySQL. - Added the
Case()
starter to all dialects to buildCASE
expressions. (thanks @k4n4ry) - Added
bob.Named()
which is used to add named arguments to the query and bind them later. - Added
bob.BindNamed
which takes an argument (struct, map, or a single value type) to be used to bind named arguments in a query. See changes tobob.Prepare()
for details of which type can be used. - Indexes now include more information such as the type, unique and comment fields.
- Constraints now include a comment field.
- Added
Checks
field to DBConstraints so that drivers can also load check constraints. (not yet supported by the SQLite driver). - Added comments field to Table definitions.
Changed
-
context.Context
is now passed toQuery.WriteQuery()
andExpression.WriteSQL()
methods. This allows for more control over how the query is built and executed.
This change made is possible to delete some hacks and simplify the codebase.- The
Name()
andNameAs()
methods of Views/Tables no longer need the context argument since the context will be passed when writing the expression. The API then becomes cleaner. - Preloading mods no longer need to store a context internally.
SetLoadContext()
andGetLoadContext()
have removed. - The
ToExpr
field inorm.RelSide
which was used for preloading is no longer needed and has been removed.
- The
-
Moved
orm.Hooks
tobob.Hooks
since it should not be limited to only ORM queries. -
Moved
mods.QueryModFunc
tobob.ModFunc
since it should be available to all packages. -
The mod capability for
orm.Setter
is now reversed. It should now be a mod for Insert and have a method that returns a mod for Update.
This makes more sense since one would at most use one setter during updates, but can use multiple setters in a bulk insert. -
table.InsertQ
has been renamed totable.Insert
. The old implementation ofInsert
has been removed.
The same functionality can be achieved in the following way://---------------------------------------------- // OLD WAY //---------------------------------------------- user, err := models.Users.Insert(ctx, db, setter) // insert one users, err := models.Users.InsertMany(ctx, db, setters...) // insert many //---------------------------------------------- // NEW WAY //---------------------------------------------- user, err := models.Users.Insert(setter).One(ctx, db) // insert one users, err := models.Users.Insert(setters[0], setters[1]).All(ctx, db) // insert many // For cases where you already have a slice of setters and you want to pass them all, you can use `bob.ToMods` users, err := models.Users.Insert(bob.ToMods(setters)).All(ctx, db) // insert many
-
table.UpdateQ
has been renamed totable.Update
. The old implementation ofUpdate
has been removed.
The same functionality can be achieved by usingmodel.Update()
ormodelSlice.UpdateAll()
. -
table.DeleteQ
has been renamed totable.Delete
. The old implementation ofDelete
has been removed.
The same functionality can be achieved by usingmodelSlice.DeleteAll()
or creating anDelete
query usingtable.Delete()
. -
BeforeInsertHooks
now only takes a singleModelSetter
at a time.
This is because it is not possible to know before executing the queries exactly how many setters are being used since additional rows can be inserted by applying another setter as a mod. -
bob.Cache()
now requires anExecutor
. This is used to run any query hooks. -
bob.Prepare()
now requires a type parameter to be used to bind named arguments. The type can either be:- A struct with fields that match the named arguments in the query
- A map with string keys. When supplied, the values in the map will be used to bind the named arguments in the query.
- When there is only a single named argument, one of the following can be used:
- A primitive type (int, bool, string, etc)
time.Time
- Any type that implements
driver.Valuer
.
-
Index
columns are no longer just strings, but are a struct to include more information such as the sort order.
Removed
- Remove MS SQL artifacts. (thanks @mbezhanov)
- Remove redundant type parameter from
bob.Load
. - Removed
Before/AfterUpsertMods
. Upserts are really just inserts with a conflict clause and should be treated as such. - Removed
Insert/InsertMany/Upsert/UpsertMany
methods fromorm.Table
since they are not needed.
It is possible to do the same thing, with similar effor using the theInsertQ
method (which is now renamed toInsert
). - Remove
Update
andDelete
methods fromorm.Table
since they are not needed.
It is possible to do the same thing, with similar effor using the theUpdateQ
andDeleteQ
methods (which are now renamed toUpdate
andDelete
). context.Context
andbob.Executor
are no longer passed when creating a Table/ViewQuery. It is now passed at the point of execution withExec/One/All/Cursor
.- Remove
Prepare
methods from table and view qureries. Sincebob.Prepare()
now takes a type parameter, it is not possible to prepare from a method since Go does not allow additional type parameters in methods. - Removed the Prisma and Atlas code generation drivers. It is better for Bob to focus on being able to generate code from the database in the most robust and detailed way and if the user wants, they can use other tools (such as prisma and atlas) to manage migrations before the code generation.
- Removed
Expressions
from Index definitions. It is now merged with theColumns
field with anIsExpression
field to indicate if the column is an expression.
Fixed
- Removed unnecessary import of
strings
inbobfactory_random.go
. - Fixed data races in unit tests. (thanks @mbezhanov)
- Fixed invalid SQL statements generated by
sm.OrderBy().Collate()
. (thanks @mbezhanov) - Fixed a bug preventing specific columns from being excluded when generating models from SQLite. (thanks @mbezhanov)
- Fixed an issue where invalid code is generated if a configured relationship has
from_where
orto_where
. - Fixed
ModelSlice.ReloadAll()
method for models with multiple primary keys.
New Contributors
- @tjmtmmnk made their first contribution in #247
- @adel-hadadi made their first contribution in #249
- @Hasaber8 made their first contribution in #265
- @mrtztg made their first contribution in #272
- @k4n4ry made their first contribution in #294
Full Changelog: v0.28.1...v0.29.0
v0.28.1
Fixed
- Also add the enum to the type array if an array of the enum is added. This is to prvent issues if the enum is only used in an array.
- Handle null column names in expression indexes. (thanks @mbezhanov)
Full Changelog: v0.28.0...v0.28.1