v0.44.0
Added
- Added PostgreSQL
MERGEstatement SQL parser used for sql-to-code generation (thanks @atzedus) - Added
R.Loadedto generated models, a nested struct with oneboolper relationship that records whether each relationship has been loaded. This disambiguates "not loaded yet" from "loaded, but no related rows" for both to-one and to-many relations. Maintained automatically byLoad*,Preload,ThenLoad, factory builds, and to-oneAttach/Insertops. TheLoadedalias can be changed in the bob config. (thanks @jacobmolby) - Added
As(alias)method tobob.BaseQuery, allowing queries (e.g.mysql.Select(...)) to be aliased directly when used as subqueries in a column list. (thanks @jacobmolby) - Added columns API: generated column structures now provide
Name() stringmethod. (thanks @atzedus) - Added
expr.ColumnsExpraccessor methods:Parent() []string,AggFunc() [2]string,AliasPrefix() string, andAliasDisabled() bool.WithParent(...)now filters empty parts, and default rendering for plain unqualified columns no longer emits redundant self-aliases (e.g."name"instead of"name" AS "name"). (thanks @atzedus) - Added
bob.ParensOmitterinterface withShouldOmitParens() boolto let expressions opt out of automatic parenthesis wrapping in expression builders. (thanks @atzedus) - Added PostgreSQL
RETURNING WITH (OLD AS ..., NEW AS ...)support forINSERT,UPDATE,DELETE, andMERGEquery builders, including fluent modifiers:im/um/dm/mm.Returning(...).WithOldAs(...).WithNewAs(...). (thanks @atzedus)- Note:
bobgen-psqlsql-to-code parsing for this syntax is currently blocked by upstream PostgreSQL parser dependency support.
- Note:
- Added PostgreSQL
TABLESAMPLE ... REPEATABLE ...support via fluent modifiers onsm.From(...)and join chains. (thanks @atzedus) - Added PostgreSQL
JOIN ... USING (...) AS aliassupport viaUsingAs(alias, cols...)on psql join chains. (thanks @atzedus) - Added PostgreSQL GROUP BY grouping-element helpers:
sm.Grouping(...),sm.Rollup(...),sm.Cube(...), andsm.GroupingSets(...). (thanks @atzedus) - Added PostgreSQL
im.ConflictTarget(...)helper for composingON CONFLICTtarget items with optional.Collate(...)and.OpClass(...)modifiers. (thanks @atzedus) - Added PostgreSQL UPDATE/MERGE tuple-assignment helper
um.SetCols(columns...)with.ToExprs(...),.ToRow(...), and.ToQuery(...)support. (thanks @atzedus) - Added PostgreSQL UPDATE/DELETE
um.WhereCurrentOf(cursor)modifier to renderWHERE CURRENT OF <cursor>. (thanks @atzedus) - Added
expr.NoSepsentinel to join expressions without any separator. The existingexpr.Joindefault (space) is unchanged. (thanks @atzedus) - Added
im.Excluded(column)helper (PostgreSQL and SQLite) forON CONFLICT DO UPDATEassignments — renders asEXCLUDED."col"with no extra space, reused internally byim.SetExcluded(...)and available for direct use inim.SetCol(...).To(...). (thanks @atzedus) - Added PostgreSQL
psql.TableFunctions(funcs)andsm.FromFunction/um.FromFunction/dm.UsingFunctionhelpers that returnbob.Expressionfor table-functionfrom_itemsources (ROWS FROM (...)when multiple functions are given). (thanks @atzedus) - Added PostgreSQL
um.From(table, joins...)anddm.Using(table, joins...)variadic join arguments so each appendedfrom_itemcan include inlineINNER JOIN,LEFT JOIN,CROSS JOIN, etc. (JoinChainbuilders). (thanks @atzedus) - Added
bobgen-psqlsupport for multipleUPDATE ... FROM/DELETE ... USINGsources: sql-to-code emitsAppendTableRef(...)per parsedfrom_itemand resolves column sources from every item. (thanks @atzedus)
Changed
- BREAKING: Renamed the generated
ThenLoadCountvariable toSelectThenLoadCountfor naming consistency withSelectThenLoad/InsertThenLoad/UpdateThenLoad. Update call sites frommodels.ThenLoadCount.X.Ytomodels.SelectThenLoadCount.X.Y. (thanks @jacobmolby) - BREAKING:
mm.SetCol()now returnsmods.Set[*mm.UpdateAction]instead of a customSetChaintype..ToExpr(val)is replaced by.To(val), and.ToDefault()is replaced by.To(psql.Raw("DEFAULT"))..To()and.ToArg()work as before. (thanks @atzedus) - BREAKING:
mm.Recursive()has been removed. PostgreSQL does not supportWITH RECURSIVEin MERGE statements. (thanks @atzedus) - BREAKING: Generated
*Columnsaccessor fields now return a dialect-specific wrapper type (e.g.,userColumn) instead of plaindialect.Expression. The wrapper still implementsdialect.Expressionand avoids extra auto-parentheses in expression builders. Use.Expressiononly when you explicitly need the embedded expression value. (thanks @atzedus) - BREAKING: PostgreSQL
UPDATE ... FROMandDELETE ... USINGadditional sources now live inUpdateQuery.FromItems/DeleteQuery.UsingItemsinstead of the embeddedclause.TableRefon the query struct. Eachum.From(...)ordm.Using(...)appends one comma-separatedfrom_item(last call no longer wins). Useum.Table(...)/dm.From(...)for the update/delete target table. (thanks @atzedus) - BREAKING: PostgreSQL
sm.FromFunctionandum.FromFunctionno longer returnFromChainor applyFROM/USINGby themselves. They returnbob.Expressionand must be passed tosm.From(...)/um.From(...)/dm.Using(...)— e.g.sm.From(sm.FromFunction(psql.F("generate_series", 1, 3)()))instead ofsm.FromFunction(...). Aliasing and other table modifiers belong onsm.From(...)/um.From(...). (thanks @atzedus) - BREAKING: PostgreSQL
sm.From/FromChainforSelectQuerynow set theFROMsource viaAppendTableRef(replace semantics) instead ofSetTable/SetTableAliason afromableinterface. (thanks @atzedus) - BREAKING: PostgreSQL
um/dmjoin helpers (InnerJoin,LeftJoin,CrossJoin, etc.) returnJoinChain[*UpdateQuery]/JoinChain[*DeleteQuery]. Use them inum.From(table, joins...)/dm.Using(table, joins...), or as standalone mods afterum.From/dm.Using—AppendJointhen attaches to the lastFromItems/UsingItemsentry. (thanks @atzedus) - BREAKING: PostgreSQL psql join chain modifiers
.Natural(),.On(),.OnEQ(),.Using(), and.UsingAs()now returnJoinChainfor fluent chaining instead ofbob.Mod. (thanks @atzedus)
Fixed
- Fix PostgreSQL
sm.Fromreplacing a previousFROMwithout clearing a stale table alias when the new source has no alias. (thanks @atzedus) - Fix PostgreSQL
sm.With(...).SearchBreadth(...)renderingSEARCH DEPTHinstead ofSEARCH BREADTHin CTE queries. (thanks @atzedus) - Avoid unnecessary imports in generated random factory code when a type has no random expression. (thanks @jay-babu)
- Fix missing base type imports (e.g.
github.com/google/uuid) in generated models when usingtype_system: "database/sql"anduuid_pkg: google, which could cause compile errors in generated many-to-many relation helpers. (thanks @atzedus) - Reuse parents when creating children in factory (thanks @abdusco)
New Contributors
Full Changelog: v0.43.0...v0.44.0