Repository navigation
A patch release on top of v0.20.0: the struct form of batch upsert asked for in #47, an explicit error for batches over the database's bind-parameter limit, and fixes found since v0.20.0.
go get github.com/coregx/relica@v0.20.1Added
BatchInsertQuery.ValuesStructs(rows)— batch upsert from structs (#47):db.BatchInsert(table, nil).ValuesStructs(nodes).OnConflict(...).DoUpdateAll()builds one multi-row INSERT … ON CONFLICT (ON DUPLICATE KEY UPDATE on MySQL) from a slice of structs or pointers of one type, read likeBatchInsertStruct(db tags, Naming, embedded structs flattened). Withnilcolumns the columns come from the struct (a single primary key that is zero in every row is left out) andValuesStructsis the only source of rows; with listed columns exactly those are read, a listed primary key must not be zero, and it mixes withValues/ValuesMap(after a derivedValuesStructsthey are an error: derived columns are sorted, a positional row would land in the wrong columns). Reachable throughExecutor.BatchInsert.BatchInsertStructis built on it. The multi-row upsert with explicit values has existed since v0.16.5
Fixed
- A batch over the database's bind-parameter limit reached the database —
BatchInsertandBatchInsertStructsend one statement, and PostgreSQL and MySQL take at most 65535 parameters (rows × columns), SQLite 32766 (its compiled default), so a large batch failed in the driver or the server. It is now an error returned before anything is sent, naming the limit and the rows per statement that fit; Relica does not split the batch or open a transaction on its own — send the rows in slices, insideTransactionalwhen they must be atomic (AGENTS.md › Batch Operations). In a transaction on MySQL and PostgreSQL the statement goes to the driver unprepared, whereinterpolateParamsor the pgx simple protocol may accept it, so the check is left to the driver there; SQLite is checked everywhere BatchInsertStructwith rows of two struct types wrote NULL for the columns the later type lacks; rows must now have one typeBatchInsertStructwrote an emptyautoidfield as""—Model().Insert()generates the ID, a batch does not; an empty autoid field (astringor a named string type) is now an error naming it- AGENTS.md › Batch Operations showed code that does not compile:
BatchInsertStruct/InsertStructwithout.Execute(), and aBatchUpdate(table, columns, key).Values(...)form that does not exist (it isBatchUpdate(table, keyColumn).Set(key, map)) - The audit missed
Update/DeletewithoutWherewhen the table is not a string literal —skills/relica/scripts/audit.sh(V4) matched onlydb.Delete("t"), sodb.Delete(table).Execute()in a loop over table names (a schema reset) ordb.Update(tableName(x))…Execute()went unreported, and the v0.20.0 error surfaced only at run time. V4 now takes any single table argument: a literal, a variable or one call
Full Changelog: v0.20.0...v0.20.1