Skip to content

Releases: stephenafamo/bob

v0.38.0

04 Jun 11:22
Compare
Choose a tag to compare

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 either database/sql or github.com/aarondl/opt/null.
    This is used to determine how to create null values in the generated code. If set to database/sql, it will use sql.Null[T] for nullable types, and if set to github.com/aarondl/opt/null, it will use opt.null.Val[T].
    The default value is database/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

31 May 10:01
Compare
Choose a tag to compare

Highlights

  1. Nullable columns are no longer generated as github.com/aarondl/opt/null.Val[T], but as database/sql.Null[T].
  2. 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 a pgx/v5 connection as a bob.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 a context.Context argument in the Commit and Rollback methods.
  • The method BeginTx on the bob.Transaction interface is now changed to Begin and it takes a single context argument.
    This is to make it easier to implement for non database/sql drivers.
  • In the generated model, the PrimaryKeyVals() method is now private.
  • Renamed driver_name to driver 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 and NewQueryer functions. Any of bob.NewDB, bob.NewTx or bob.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 of github.com/aarondl/opt/null.Val.
    • Optional values are now represented as pointers instead of github.com/aarondl/opt/omit.Val[T].
  • 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 the imports 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 in mysql 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

27 May 17:19
Compare
Choose a tag to compare

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

27 May 11:20
Compare
Choose a tag to compare

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

27 May 00:18
Compare
Choose a tag to compare

Fixed

  • Store types.Time as an RFC3339 string in the DB

Full Changelog: v0.35.0...v0.35.1

v0.35.0

26 May 19:20
Compare
Choose a tag to compare

Added

  • Added support to generate code for SELECT, INSERT, UPDATE and DELETE queries in bobgen-mysql.
  • Added support to generate code for INSERT, UPDATE and DELETE queries in bobgen-sqlite.
  • Added LIMIT and OFFSET to the SQLite Update and Delete queries.
  • Added IndexedBy and NotIndexed mods to the SQLite Delete queries.
  • Added the Transactor and Transaction 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 merges clause.Table and clause.From since they had overlapping functionality.
  • Added RunInTx method to bob.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 MySQL SELECT queries. These are applied to the result of a UNION, INTERSECT or EXCEPT query.
  • Added type_limits property to column definitions.
  • Added limits option to random_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 the pg_snapshot and txid_snapshot type in PostgreSQL.
  • Added a custom Time type to the types package. This is motivated by the fact that the libsql driver does not support the time.Time type properly.
  • Added an option to disable aliasing when expressing orm.Columns. Also added EnableAlias and DisableAlias methods to orm.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 and TableNotIndexed to IndexedBy and NotIndexed.

  • Use LIBSQL_TEST_SERVER environment variable to run tests against a libSQL server instead of the hardcoded localhost:8080.

  • BeginTx now returns a Transaction interface instead of a bob.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 like Preload.User.Pilots(), instead of PreloadUserPilots().

  • In the generated model code, ThenLoad is now a struct and has been split for each query type.
    It is now used like SelectThenLoad.User.Pilots(), instead of ThenLoadUserPilots().

  • 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 using One, All, Cursor now immediately return orm.ErrCannotRetrieveRow instead of executing the query first.

  • Generated tests are now run when testing drivers.

  • MEDIUMINT and MEDIUMINT UNSIGNED are now generated as int16 and uint16 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 as pgtypes.Snapshot instead of pgtypes.TxIDSnapshot.

  • cidr postgres type is now generated as types.Text[netip.Prefix] instead of types.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 with WithParentsCascading which also includes parents for any parent relationships.

Removed

  • Removed clause.Table and clause.From, and merge into clause.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 with pgtypes.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

30 Apr 23:44
Compare
Choose a tag to compare

Fixed

  • Fix bug with bobgen-sql parsing of string identifiers in certain cases.

Full Changelog: v0.34.1...v0.34.2

v0.34.1

30 Apr 23:20
Compare
Choose a tag to compare

Fixed

  • Remove unnecessary limitation to place FETCH WITH TIES before OFFSET.
  • Fix issue with verifying statements in bobgen-psql.

Full Changelog: v0.34.0...v0.34.1

v0.34.0

29 Apr 23:58
Compare
Choose a tag to compare

Added

  • Added support to generate code for UPDATE, and DELETE queries in bobgen-psql.

Changed

  • Changed to non-cgo version of postgres parser.
  • Changed the dir configuration for bobgen-sql to pattern 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

26 Apr 19:27
0c65b87
Compare
Choose a tag to compare

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