Skip to content

v0.4.0

Latest

Choose a tag to compare

@kiplagatcollins kiplagatcollins released this 28 Nov 10:50
· 8 commits to main since this release

Fixed

  • Composite primary keys no longer bind, order, or paginate by the first key column alone (audit groups D/Q):
    • Scalar id conditions (First/Find/Take/Last/Delete(&m{}, 42)) on a composite-key model return ErrInvalidValue instead of matching every row sharing PKs[0]. Single-key behavior is unchanged.
    • Save matches updates on the full key tuple (a = ? AND b = ?) and inserts when any key field is zero; FirstOrCreate treats a row as persisted only when the whole tuple is set.
    • First/Last order by the full key tuple, making results deterministic when the first key column ties.
    • FindInBatches paginates composite keys with row-value keyset comparison ((a, b) > (?, ?) ORDER BY a, b), gated on the new feature.RowValues flag (declared by the SQLite and PostgreSQL dialects); dialects without it get a clear unsupported-feature error.
    • SQLite LastInsertID backfill no longer overwrites client-assigned composite key fields with the rowid.
    • Relation inference fails loudly instead of guessing: belongs-to onto a composite-key table requires an explicit references column; has-one/has-many/many2many on a composite-key side are rejected at parse time (single-column relations onto composite tables via explicit tags keep working).

Performance

  • Statement is embedded by value in DB: every chain hop costs one allocation instead of two.
  • The 16 canonical clause names live in an inline slot array + presence bitmask; the Clauses map and Order slice now exist only for custom (plugin) clause names. AddClause/RemoveClause/Clause and clone are allocation-free for standard clauses (Count no longer allocates to strip ORDER BY).
  • Association callbacks bail out immediately for models with no relations, and no longer format a discarded error when Dest is nil (Update had been paying ~6 allocs/op on this path).
  • logger.Tracer (optional interface implemented by both built-in loggers): the query path checks WouldTrace before allocating the trace closure, so gated loggers pay nothing per statement.
  • BuildClauses reuses the previous build's buffer on rebuilds.
  • Measured (benchcmp, in-memory SQLite, interleaved n=10): allocation geomean 97/op vs bun 126 (+29%) and gorm 249 (+155%). Time geomean leads bun by ~8% and gorm by ~47% on this run.

Added

  • feature.RowValues dialect flag (SQLite, PostgreSQL).