Releases: stephenafamo/bob
v0.38.0
Highlights
It is now possible to restore the null type system from < v0.37.0
by adding fallback_null: github.com/aarondl/opt/null
to your bobgen.yaml
configuration file.
Added
- Added the
fallback_null
top level configuraiton option. Which can be eitherdatabase/sql
orgithub.com/aarondl/opt/null
.
This is used to determine how to create null values in the generated code. If set todatabase/sql
, it will usesql.Null[T]
for nullable types, and if set togithub.com/aarondl/opt/null
, it will useopt.null.Val[T]
.
The default value isdatabase/sql
.
Fixed
- Correctly build models with nested relationships in the factory.
- Fix a performance issue with code generation in
bobgen-psql
. - Use the correct alias when generating table columns.
- Fix issue with generating factory code for tables with schema names.
Full Changelog: v0.37.0...v0.38.0
v0.37.0
Highlights
- Nullable columns are no longer generated as
github.com/aarondl/opt/null.Val[T]
, but asdatabase/sql.Null[T]
. - Optional fields (e.g. in setters) are no longer generated as
github.com/aarondl/opt/omit.Val[T]
but as pointers.
Unfortunately, this will require a lot of changes to existing code that depends on the previously generated types.
However, I believe this is a better direction as it uses only the standard library.
Added
- Added the
drivers/pgx
package which contains types and functions to use apgx/v5
connection as abob.Executor
. - Added support for
github.com/ncruces/go-sqlite3
. (thanks @ncruces) - Added support for configuring what type to generate specific null versions of a type instead of always wrapping with
sql.Null[T]
.
Changed
- The
bob.Transaction
interface now takes acontext.Context
argument in theCommit
andRollback
methods. - The method
BeginTx
on thebob.Transaction
interface is now changed toBegin
and it takes a single context argument.
This is to make it easier to implement for nondatabase/sql
drivers. - In the generated model, the
PrimaryKeyVals()
method is now private. - Renamed
driver_name
todriver
in code generation configuration. - In type replacements, nullability is not used in matching.
Previously, nullability of matches was set to false by default, and would require an additional replacement to also match nullable columns.
Removed
- Removed the
New
andNewQueryer
functions. Any ofbob.NewDB
,bob.NewTx
orbob.NewConn
can be used instead. - Removed the
StdInterface
interface as it is unnecessary. - Remove redundant
orm.Model
interface. - Remove dependence on
github.com/aarondl/opt
in generated code.- Nullable values are now wrapped
database/sql.Null
with instead ofgithub.com/aarondl/opt/null.Val
. - Optional values are now represented as pointers instead of
github.com/aarondl/opt/omit.Val[T]
.
- Nullable values are now wrapped
- Removed
in_generated_package
type configuration option. This was limited and could only indicate that the type is in the models package.
Instead the full import path can now be used in theimports
configuration option, and if it is in the same package as the generated code, the prefix will be automatically removed.
Fixed
- Properly handle
nil
args when checking if default or null inmysql
table insert query. - Fix bug in querying slice relationships in MySQL and SQLite.
New Contributors
Full Changelog: v0.36.1...v0.37.0
v0.36.1
Fixed
- Fixed issue with generating correct test code for nullable args in SQL queries.
- Fix issue where writing the "NO EDIT Disclaimer" at the top of Go generated files was skipped.
Full Changelog: v0.36.0...v0.36.1
v0.36.0
Changed
-
Loaders are now generated as singular instead of plural. This feels more natural when using them in code.
// Before models.Preload.Users.Pilots() models.SelectThenLoad.Users.Pilots() // After models.Preload.User.Pilots() models.SelectThenLoad.User.Pilot()
Full Changelog: v0.35.1...v0.36.0
v0.35.1
v0.35.0
Added
- Added support to generate code for
SELECT
,INSERT
,UPDATE
andDELETE
queries inbobgen-mysql
. - Added support to generate code for
INSERT
,UPDATE
andDELETE
queries inbobgen-sqlite
. - Added
LIMIT
andOFFSET
to the SQLite Update and Delete queries. - Added
IndexedBy
andNotIndexed
mods to the SQLite Delete queries. - Added the
Transactor
andTransaction
interfaces. - Added the
SeparatePackageForTests
attribute to generation outputs to indicate if generated tests should have their own package. - Added the
RandomColumnNotNull
mod to factories to generate random values for non-nullable columns without the chance of being null. - Added the
WithOneRelations
mod to factories to include every relation for a factory template. - Added
clause.TableRef
which mergesclause.Table
andclause.From
since they had overlapping functionality. - Added
RunInTx
method tobob.DB
. This starts a transaction and calls the given function with this transaction. - Add support for MySQL to
bobgen-sql
. - Added
Exec
test for generated queries that do not return rows. - Added
OrderCombined
,LimitCombined
,OffsetCombined
mods to MySQLSELECT
queries. These are applied to the result of aUNION
,INTERSECT
orEXCEPT
query. - Added
type_limits
property to column definitions. - Added
limits
option torandom_expr
function for types. This is to pass any column limits to the randomization function (e.g.max_length
for strings). - Added tests to check that the generated factory can create models and save into the database.
- Added the
pgtypes.Snapshot
type for thepg_snapshot
andtxid_snapshot
type in PostgreSQL. - Added a custom
Time
type to thetypes
package. This is motivated by the fact that thelibsql
driver does not support thetime.Time
type properly. - Added an option to disable aliasing when expressing
orm.Columns
. Also addedEnableAlias
andDisableAlias
methods toorm.Columns
to control this behavior. - Added a
PrimaryKey
method to{dialect}.Table
to get the primary key columns of the table.
Changed
-
Changed the INDEXED BY and NOT INDEXED mods for SQLite update queries from
TableIndexedBy
andTableNotIndexed
toIndexedBy
andNotIndexed
. -
Use
LIBSQL_TEST_SERVER
environment variable to run tests against a libSQL server instead of the hardcodedlocalhost:8080
. -
BeginTx
now returns aTransaction
interface instead of abob.Tx
. -
Generated tests that required a database connection no longer create a new connection for each test. Instead it depends on a
testDB
connection that the user has to provide. -
In the generated models, relationships for
ModelSlice
are now loaded using arrays to reduce the number of parameter in the query.-- Before SELECT * FROM pilots WHERE jet_id IN ($1, $2, $3, ...); -- Parameters increase with the number of pilots -- After SELECT * FROM pilots WHERE jet_id IN (SELECT unnest(CAST($1 AS integer[])); -- Parameters are always 1
-
In the generated model code,
Preload
is now a struct instead of multiple standaalone functions.
It is now used likePreload.User.Pilots()
, instead ofPreloadUserPilots()
. -
In the generated model code,
ThenLoad
is now a struct and has been split for each query type.
It is now used likeSelectThenLoad.User.Pilots()
, instead ofThenLoadUserPilots()
. -
In the generated model code, the Load interfaces no longer include the name of the source model since it is a method on the model.
It now looks like*models.User.LoadPilots
instead of*models.User.LoadUserPilots
. -
Made changes to better support generating code in multiple languages.
-
Mark queries with
ON DUPLICATE KEY UPDATE
as unretrievable in MySQL. -
Unretrievable
INSERT
queries usingOne, All, Cursor
now immediately returnorm.ErrCannotRetrieveRow
instead of executing the query first. -
Generated tests are now run when testing drivers.
-
MEDIUMINT
andMEDIUMINT UNSIGNED
are now generated asint16
anduint16
respectively. This is because Go doe not support 24 bit integers. -
The randomization function for floats, strings, and decimals now respect the limits set in the column definition.
-
txid_snapshot
is now generated aspgtypes.Snapshot
instead ofpgtypes.TxIDSnapshot
. -
cidr
postgres type is now generated astypes.Text[netip.Prefix]
instead oftypes.Text[netip.Addr]
. -
money
postgres type is now generated as a string with a custom randomization expression instead of a decimal. -
Factory template mods now take a context argument. This allows for more control when using recursive mods.
-
Removed
WithOneRelations
mod from factories, now replaced withWithParentsCascading
which also includes parents for any parent relationships.
Removed
- Removed
clause.Table
andclause.From
, and merge intoclause.TableRef
since they had overlapping functionality. - Remove unnecessary context closure in generated join helpers.
- Remove the deprecated
wipe
generation option. - Remove
pgtypes.TxIDSnapshot
type. This is now replaced withpgtypes.Snapshot
.
Fixed
- Use correct row name for generated queries in
bobgen-sqlite
. - Properly select query comment in
bobgen-sqlite
. - Fixed issue with using generated queries with
VALUES
as mods. - Moved
Partitions
in MySQL delete queries to after the table alias. - Fixed issue with inserting into a table with all rows having default values in SQLite.
- Use table name and not table alias in SQLite returning clause since the alias is not available in the
RETURNING
clause. - Fixed generated unique constraint errors for SQLite.
- Correctly resuse inserted rows in factories.
Full Changelog: v0.34.2...v0.35.0
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