All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Add PreloadAs PreloadOption to override the join alias when preloading a relationship with a left join. (thanks @daddz)
- Add
AliasedAs()
method totableColumns
andtableWhere
types to use a custom alias.
- Remove
TableWhere
function from the generated code. It was not used by the rest of the generated code and offered no clear benefit.
- Use
netip.Prefix
instead ofnetip.Addr
for postgres inet column type. This makes it possible to contain a subnet. - Allow underscores in enum variable names.
- Fix an issue with title casing enum values
- Add
bobgen-sql
a code generation driver for SQL schema files. Supports PostgreSQL and SQLite. - Add new properties
compare_expr
andcompare_expr_imports
to thetypes
configuration. This is used when comparing primary keys and in testing. - Add
never_required
to relationships configuration. This makes sure the factories does not require the relationship to be set. Useful if you're not using foreign keys. (thanks @jacobmolby) - Add wrapper types for Stringer, TextMarshaler/Unmarshaler, and BinaryMarshaler/Unmarshaler to the
types
configuration. - Make generated enum types implement the
fmt.Stringer
,encoding.TextMarshaler
,encoding.TextUnmarshaler
,encoding.BinaryMarshaler
andencoding.BinaryUnmarshaler
interfaces.
- Properly detect reference columns for implicit foreign keys in SQLite.
- Fix panic when generating random values for nullable columns. (thanks @jacobmolby)
- Sort relationships and imports for deterministic generated code. (thanks @jacobmolby)
- Correctly allow
OVER ()
with an empty window definition in PostgreSQL. (thanks @relvacode) - Set
GROUP BY
toNULL
if there are no expressions to group by. - Replace symbols in enum values with their unicode point to make them valid Go identifiers.
- Properly detect implicit foreign keys in SQLite.
- Fix issue with attaching multi-sided relationships. (thanks @jacobmolby)
- Update
github.com/jaswdr/faker
dependency fromv1
tov2
- Add randomization for all primitive types
- Add test for factory type randomization
- Drivers are now required to send in type definitions for generated types
- Custom types can now be configured at a top level in the config file
- Format generated files with
gofumpt
- Replace key in
replacements
configuration is now a string referring to the type defined in thetypes
configuration.
- Remove
Imports
from column definition.
INTEGER
columns are now correctly generated asint32
notint
- Fix panic when inferring
modify
for relationships with no primary key - Skip factory enum generation if there are no enums
- Return
sql.ErrNoRows
when Insert/Upsert returns nothing
- Do not wrap
Setter.Expressions()
in parenthesis
- Add
bob.Cache()
which saves the built SQL and args to prevent rebuilding the same query multiple times. - Add
As()
starter to alias expressions - Add
OP()
builder method for using custom operators - Add
table.InsertQ(ctx, db)
now includes the insert columns from the table model. - It is now possible to configure additional constraints for code generation.
- Add
um.SetCol()
which maintains the old behavior ofum.Set()
. - Generate additional
Expressions()
method for Setters to make it easier to use them inum.Set()
orim.Set()
.
- Aliases configuration for code generation no longer has a top level
table
key - When configuring relationships,
from_unique
,to_unique
,key_nullable
can no longer be configured. They are now inferred from the database. - When configuring relationships,
to_key
has been changed tomodify
and should be set tofrom
,to
or""
to indicate which side of the relationship to modify. If left empty, Bob will try to guess which side to modify based on the presence of primary keys and unique columns. RelWhere.Value
is nowRelWhere.SQLValue
- Change CONFLICT/DUPLICATE KEY UPDATE to use mods instead of a chainable methods.
- Change
um.Set()
to take a list of expressions. - Rename Setter method from
Insert()
toInsertMod()
to avoid confusion.
- Prevent generating duplicate relationships for many-to-many self-join relationships
- Correctly use table alias in generated relationship join mods
- Fix an issue where CTEs were encased in double parenthesis
- Fix invalid SQL generated when doing
JOIN USING
- Correctly include "AS" in function query if alias is set
- Setters are also generated for tables that have relationships, even if they have no primary key
- Column aliases in CTEs are now correctly included in the final query
- Fix several issues with generating code for multi-sided relationships
- Fix an issue where loading many-to-many relationships cause no columns to be selected unless specified
- Fix an issue where many-to-many relationships would not be able to use nested loaders
- Expand expressions when used in Raw (thanks @RangelReale)
- Add
InsertQ
,UpdateQ
, andDeleteQ
methods to Table models to start INSERT, UPDATE and DELETE queries respectively. - Allow column comment for replacement matching (thanks @jroenf)
- Add table query hooks to modify model queries
- Include
WhereOr
andWhereAnd
to make it easier to combine multiple generated where clauses - Print a warning if a replacement rule did not find a match (thanks @jacobmolby)
- Export generated factory.Factory struct
- Allow Limit and Offset to be used as Arguments in PostgreSQL (thanks @RangelReale)
- Make model hooks take slices not single objects
- Return rows affected from
Exec()
method of view queries instead ofsql.Result
- Chain comparison methods now take an
Expression
instead ofany
- Table models now require the types to implement
orm.Table
andorm.Setter
interfaces.
- Remove UpdateAll and DeleteAll methods on the Table models.
- Honor Only and Except in sqlite driver
- Always surround subqueries with parenthesis when used as an expression
- Fix mysql
TablesInfo
method and make sure we don't exclude entire table when targeting columns (thanks @jacobmolby) - Fix bug in sqlite foreign key and join table detection
- Fix
Upsert
andUpsertAll
methods ofmysql.Table
- Force uniqueness of relationship names in
psql
driver
- Fix panic when attaching associated relationships
- Make getting a random integer for preloading thread-safe
- Check all members when loading relationships
- Fix panic in Insert/Attach Relationship loop
- Replace
huandu/go-clone
withqdm12/reprint
- Fix cloning bug by replacing
jinzhu/copier
withhuandu/go-clone
- Account for windows when calculating models module path
- Update the generated code to use
github.com/gofrs/uuid/v5
- Fix bug where auto-increment columns were marked as generated in the SQLite driver
- Add the
PreloadWhere
preload mod to filter what relation should be preloaded. ViewQuery
now embedsbob.BaseQuery
giving it additional methods likeApply
andBuild
- Add plugin support. Currently 3 plugin hooks are provided.
PlugState
,PlugDBInfo
andPlugTemplateData
.
- Make
View.Name()
return a dialect-specific expression - Improve
Debug
helpers.Debug
writes query output to stdoutDebugToWriter
writes the query output to anyio.Writer
with a fallback to stdout.DebugToPrinter
prints the query with a givenbob.DebugPrinter
. Also falls back to stdout.
- Rename
OnlyColumns
toPreloadOnly
andExceptColumns
toPreloadExcept
to be more consistent with the newly addedPreloadWhere
. JoinChain.On
now takes Expressions instead ofany
.JoinChain.Using
now takes strings instead ofany
.- Export
gen.TemplateData
- Remove
ILIKE
operator from MySQL since it is not supported. - Removed
Destination()
method in driver interface. - Removed
PackageName()
method in driver interface.
- Account for possible clashes between column and relationship alias
- Make
Preload
mods work the same way as other query mods - Avoid overwriting manually flipped relationships.
- Account for potentially null relationship in Load methods
- Fix
On
method for JoinChain inmysql
andsqlite
- Add
LIKE
andILIKE
operators - Print generated files
- Add
no_reverse
option for user-configured relationships
- Move common parts of loading to shared internal package
- Fix generated joins for multi-sided relationships
- Account for relationships with tables that do not have a primary key in models and factories
- Properly extract preloaders nested in
mods.QueryMods
- Fix bug in preloading with multiple sides
- Fix issue with multi-sided relationships that include views
- Make self-referencing foreign keys work
- Tweak factory types to make collisions even less likely
- Comparison methods now require an expression (
bob.Expression
)
- No more
X
builder start function - No more
P
builder method
- Fix bug with args in table updates
- Fix some typos in documentation (thanks @leonardtan13)
- Fix a bug when multiple multi-column foreign keys exist
- Multiple internal changes to the generator to make it easier to write a custom entrypoint
- More robust testing of code generatio