Repository navigation
v0.40.0
Highlights
Code generation is now modular and depends on plugins.
See the plugins configuration documentation to understand how to choose what is generated..
Added
- Made code generation modular by relying on built-in plugins that can be enabled or disabled in the configuration.
dbinfo: Generates code for information about each database. Schemas, tables, columns, indexes, primary keys, foreign keys, unique constraints, and check constraints.enums: Generates code for enums in a separate package, if there are any present.models: Generates code for models. Depends onenums.factory: Generates code for factories. Depends onmodels.dberrors: Generates code for unique constraint errors. Depends onmodels.where: Generates type-safe code forWHEREclauses in queries. Depends onmodels.loaders: Adds templates to themodelspackage to generate code for loaders e.gmodels.SelectThenLoad.Table.Rel().joins: Adds templates to themodelspackage to generate code for joins e.gmodels.SelectJoin.Table.LeftJoin.Rel.queries: Generates code for queries.
- Added new
types.Uint64type that sends values to the database as strings. This is necessary because usinguint64directly can cause an overflow if the value exceeds the maximum value of anint64. This is a limitation imposed bydatabase/sql/driver.Valuerinterface. - Added support for
pgvectortypes during code generation.pgvector.Vectorpgvector.HalfVectorpgvector.SparseVector
Changed
- Enums are now imported directly from a new generated
enumspackage. This makes it easier to use enums in other packages without having to depend on themodelspackage. - Preload functions now take a custom
orm.PreloadRelstruct instead of reusingorm.Relationship. - By default, factories are now generated in
./factoryinstead of./models/factory. - Outputs are now determined by plugins which can be enabled or disabled in the configuration.
- UniqueConstraintErrors are now generated in a separate
dberrorspackage instead of being generated in themodelspackage. - Tests in the generated
modelspackage are no longer generated in a separatemodels_testpackage. There is no longer any circular dependency since tests for the unique constraint errors are generated in thedberrorspackage. orm.Columnshas been moved toexpr.ColumnsExpr.orm.NewColumnshas been moved toexpr.NewColumnsExpr.<Table>.Columns()is removed. The columns expression is now expected to be embedded in theColumnsfield of the<Table>struct.<dialect>.Viewand<dialect>.Tablenow take an additional type parameter for the columns type. This is assigned to theColumnsfield withNewView/NewTablefunctions.
Removed
- Removed the
no_factoryconfiguration option. It is now replaced with thefactoryplugin which can be enabled or disabled. See https://bob.stephenafamo.com/docs/code-generation/configuration#plugins-configuration for more details. - Removed the
OnlyandExceptexported functions inorm. They are now in the privateinternalpackage. - Removed the generated
models.<Model>Columnsglobal variable. It can now be accessed throughmodels.<Table>.Columns. - Removed the generated
models.TableNamesandmodels.ColumnNamesglobal variables. Their use can be replaced with thedbinfoplugin which generates adbinfopackage with all the information about the database.
Fixed
- Fixed issue with redundant title casing column names in query templates. (thanks @luiscleto)
- Fix invalid expression with pointer-based type systems. (thanks @tak848)
- Fix panic when parsing SQLite
UPDATEqueries that do not contain aFROMclause. - Fix issue when using enums in generated queries.
- Fix randomization of floats and decimals in the factory.
- Fix JSON data being incorrectly hex-encoded as bytea when using pgx through simple protocol, causing PostgreSQL to reject it with invalid input syntax errors. (by @Maxitosh)
- Fix issue with preload queries not using a defined schema on the related tables
New Contributors
Full Changelog: v0.39.0...v0.40.0