Repository navigation
Added
-
Generated custom query rows now honor configured serialization tags and casing, including nested results and ignored result columns. Duplicate SQL labels keep distinct serialization keys. See #762. (thanks @ChrisJr404)
-
bobgen-psqlnow acceptsgithub.com/jackc/pgx/v5(native pgx, used withgithub.com/stephenafamo/bob/drivers/pgx) as thedriveroption. Support is experimental: array andtsvectorcolumns work (tsvectoris generated aspgtypes.TSVector, since pgx v5.9 and later cannot scan it into astring), but some other types such asinterval,bit,bit varyingand"char"are not yet scannable by native pgx into the generated Go types. -
pgtypes.Array[T]andpgtypes.EnumArray[T]now implementpgtype.ArrayGetterandpgtype.ArraySetter, so native pgx scans and encodes them directly. TheirScanmethod also decodes pgx's binary array format, so they work when wrapped in anothersql.Scannersuch asnull.Val,sql.Nullororm.NullTypeConverter. With the native pgx driver, every array column is generated aspgtypes.Array[T]; thelib/pqandpgx/v5/stdlibdrivers keep generating the same types as before. See #90 and #739. -
Added
(*bob.Load).NextUniqueInt(), which is likebob.NextUniqueInt()but only unique within a query, so aliases built with it are the same every time the query is built (#741).
Changed
-
MySQL custom queries now infer a nullable Go argument for
UPDATE ... SET column = ?when the column acceptsNULL. Regenerate and pass the configured nullable type, or annotate the parameter/* ::notnull */to keep the previous signature (#516). -
pgtypes.EnumArray[T]is now an alias ofpgtypes.Array[T].github.com/stephenafamo/bob/types/pgtypesnow importsgithub.com/jackc/pgx/v5/pgtype. -
BREAKING: The minimum supported Go version is now 1.25 (
go 1.25.0ingo.mod), becausegithub.com/jackc/pgx/v5v5.9 requires it. Projects on Go 1.24 or older can no longer build bob and must upgrade their Go toolchain. -
Upgraded
github.com/jackc/pgx/v5to v5.9.2,golang.org/x/textto v0.41.0,golang.org/x/cryptoto v0.55.0,github.com/moby/go-archiveto v0.3.0,github.com/go-viper/mapstructure/v2to v2.4.0 andgithub.com/docker/dockerto v28.3.3 to fix advisories reported bygovulncheck. Other modules moved only as required by these upgrades.golang.org/x/cryptov0.56.0, which fixes GO-2026-6354 and GO-2026-6355, requires Go 1.26 and is not included.
Fixed
-
Fixed filtered relationship inserts referencing a related row before it was created. Generated relationship queries use the configured
sql_valueas SQL, consistent with preloading: quote SQL text literals in the config (e.g.sql_value: "'active'"). A relationship configured under the wrong source table now fails generation with a diagnostic instead of producing invalid Go (#553). -
Exists,AnyandAllnow render query operands withWriteQueryand supply the required parentheses. This fixes generated relationshipWherefilters that SQLite rejected asEXISTS ((SELECT ...)). Non-query operands such asArgandRawkeep their surrounding parentheses (#742). (thanks @evanmarshall) -
Fixed generated factory relationship modifiers recursing until stack overflow when given existing models with loaded bidirectional relationships. Factories now stop at a cycle while preserving loaded relationships shared by separate branches (#761).
-
Fixed the libSQL generator test to use the port assigned by Testcontainers. The PostgreSQL generator test now cleans up after a failed container start and reports setup errors as test failures. See #747. (thanks @dmakushin)
-
Fixed generated relationship code for a
to_wherewith a literalgo_valuesuch astrueor1under thedatabase/sqlandgithub.com/aarondl/opt/nulltype systems. The setter took the address of the literal (&true), which does not compile. See #553. -
Generated factories now insert a child with its explicitly requested optional parent’s foreign key when the relationship is a plain foreign key. This avoids a follow-up
UPDATEand its audit or versioning side effects. See #769. -
Generated factories use the requested endpoints on the first insert of a many-to-many bridge with two required parent relationships and its own model. This avoids unlinked parent rows and a follow-up bridge update (#620).
-
Fixed
bobgen-psqlcutting off the closingENDof aCASEexpression when building the mods for a query, so a query likeUPDATE ... SET col = CASE ... END WHERE ...produced invalid SQL. See #767. -
Fixed the generated
<Table>Slice.copyMatchingRows(used byUpdateAll,ReloadAll, and theUpdateMod/DeleteMod/MergeModloaders) dropping relationship and plugin caches when refreshing a slice in place. It used to swap each slice element for a freshly scanned model after copying over only.R, silently losing.Cand any other non-column field. It now copies just the column fields onto the existing model instead, so the slice keeps its original pointers and all its cached fields. See #759 for the full rationale. Note: code relying on pointer identity changing acrossUpdateAll/ReloadAllwill now observe the same pointer, and models returned by a caller-driven.All()call are no longer mutated with.R. -
BREAKING: Fixed the generated single-model
(*Foo).Updateand(*Foo).Reloadsilently clearing relationship and plugin caches on every call. Both methods used to overwrite the receiver wholesale (*o = *v) with the freshly scanned row, which zeroed out every non-column field — the relationship cache.R(includingR.Loaded), the counts plugin's.C, and anything a plugin adds viamodel/fields/additional. They now copy only the column fields instead, so those caches survive. See #758 for the full rationale.Breaking change: code relying on
Update()/Reload()clearing.R(e.g. a "reload if not loaded" pattern keyed offR.Loaded.<Rel>) will stop reloading, sinceR.Loaded.<Rel>now staystrue. The same applies to.C. -
Generated
AfterQueryHookmethods no longer assign an unused context. Generated count preload helpers now return a writer error if they cannot write theASseparator before an alias. See #774. (thanks @edi-oai) -
Generated single-model
UpdateandDeleterun the before and after model hooks, as their slice counterparts do. A before-hook error prevents the write (#616). -
BREAKING: The generated
Preload(name, retrieved)method and the single-modelLoad<Rel>methods now append the current parent to a to-many back-reference instead of replacing it with a one-element slice holding only that parent. This is a regression fix, not a new choice of semantics:orm.Preloadshares one related-struct instance across every parent row with the same join key ("dedup"), added opt-in asorm.PreloadDedupin commit8d9485c(2026-07-12) and made unconditional four days later by commit76abd64(2026-07-16), which dropped the opt-in gate sobuildPreloadertakes the dedup path whenever the join key is resolvable. Both commits shipped as PR #736 in v0.50.0 — not v0.49.0, even though the closest CHANGELOG description of dedup ("Preloadnow shares a single related-struct instance...", still above) is filed under the already-released v0.49.0 section, a merge artifact from PR #736 landing after the v0.49.0 tag. That description also never mentions that dedup started as opt-in or that removing the gate changes what a to-many back-reference can hold — the gap this entry fills.Before dedup,
Preloadand the single-modelLoad<Rel>methods built a fresh child instance per parent, so overwriting the back-reference with<Parent>Slice{o}and appending to it produced the same result — the choice between them was an invisible implementation detail. Once dedup shares a child across parents (which is now the default path for any to-one relationship whose inverse is to-many — the common case, since a to-one relationship's inverse is a to-many "has many" back-reference), the overwrite branch replaces the shared child's back-reference on every write, so only the last parent to process it survives; every other parent silently disappears fromR.<Parents>. The slice loaders (<Parent>Slice.Load<Rel>) never had this bug — they always appended. All four overwrite sites now use that same plainappendform, so every path agrees on what a to-many back-reference holds, and the result matches whatThenLoadhas always produced for the same data.Breaking change: now that a shared child is bob's default outcome for a dedup-eligible relationship (not just a caller-constructed edge case), any caller relying on the previous overwrite behaviour — including plain default-configuration JOIN
Preloadcalls that happen to preload a relationship shared by multiple parents — will see every parent accumulate in the back-reference instead of just the last one. CallingPreloadtwice with the same parent adds that parent twice, matching the pre-existing non-deduplicating behaviour of the slice loaders andThenLoad. -
Fixed
QueryStmt.All(the prepared-statement path returned byPrepareQueryx) silently falling back to per-elementAfterQueryHookcalls when the slice type is notHookableTypebut the single/element type is, instead of returningErrHookableTypeMismatchlikeAllx(the non-prepared path) already does for the same type combination. Breaking change: code on the prepared path relying on the undocumented fallback for this type combination now receivesErrHookableTypeMismatchinstead of silently succeeding. Generated code is unaffected, since generated<Table>Slicetypes always implementAfterQueryHook. -
Fixed the PostgreSQL code generator assigning query argument types by the
$Nwritten in the query rather than the$Nthe parser renumbers it to (e.g.WHERE email_validated = $2 AND primary_email = $1typing$1asbool), which gave the generated function its argument types in the wrong order. Argument names and bind positions were already correct, so only the types moved (#753). (thanks @tak848) -
Close attached sqlite temp files inside the loop (thanks @eliseomartelli)
-
Fixed
Preloadand generated joins through another table (such asSelectJoins.Videos.InnerJoin.Tags) giving the joined tables a different alias every time a query was built ("users_10001", then"users_10002", ...). The aliases are now numbered per query instead of per process, so the same query always results in the same SQL. This lets drivers that cache prepared statements by their SQL, such aspgx, reuse the statement, keeps every execution from adding an entry topg_stat_statementson PostgreSQL 18, and stops the aliases from getting longer until the"alias.column"name of a preloaded column passes PostgreSQL's limit of 63 bytes (#741). Note: code that calls aPreloaderfunction directly now has to apply the mod it returns before using the returned mapper mod and loaders. -
Fixed the psql
UPDATE ... FROMandDELETE ... USINGclauses double-counting preceding arguments when numbering placeholders: after e.g. twoSETarguments, a parameterizedFROM (VALUES ...)source started at$5instead of$3, generating SQL that referenced placeholders beyond the returned argument slice. The from-item helper now follows thebob.Express*contract — it takes only the placeholder offset and returns just the newly generated arguments (#772, #786). (thanks @dmakushin)
New Contributors
- @xrn made their first contribution in #770
- @eliseomartelli made their first contribution in #787
- @akashchamp made their first contribution in #779
- @theluckystrike made their first contribution in #780
- @edi-oai made their first contribution in #774
- @finleyjb made their first contribution in #778
- @evanmarshall made their first contribution in #743
- @ChrisJr404 made their first contribution in #762
Full Changelog: v0.50.0...v0.51.0