Skip to content

v0.35.0

Compare
Choose a tag to compare
@stephenafamo stephenafamo released this 26 May 19:20
· 71 commits to main since this release

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