Upsert

zio.blocks.sql.Upsert
object Upsert

Builders for SQLite/PostgreSQL upsert Frags.

Every produced Frag follows the invariant parts.length == params.length + 1 and is rendered via dialect.paramPlaceholder (both dialects use ?). Identifiers are validated through SqlIdentifier.validate and quoted with double quotes in the conflict clause. Assignment columns are additionally validated against Table.columns.

Attributes

Source
Upsert.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Upsert.type

Members list

Value members

Concrete methods

def buildDoNothingSuffix(conflictColumn: String): Frag

Alias used by prior docs.

Alias used by prior docs.

Attributes

Source
Upsert.scala
def buildDoUpdateSuffix(conflictColumn: String, assignments: IndexedSeq[(String, DbValue)]): Frag

Alias used by prior docs.

Alias used by prior docs.

Attributes

Source
Upsert.scala
def doNothing(tableName: String, columns: IndexedSeq[String], values: IndexedSeq[DbValue], conflictColumn: String): Frag

Low-level builder: full INSERT with DO NOTHING.

Low-level builder: full INSERT with DO NOTHING.

Value parameters

columns

column names in order, each validated

conflictColumn

validated and quoted in suffix

tableName

validated via SqlIdentifier

values

values aligned with columns

Attributes

Source
Upsert.scala
def doNothingRaw(tableName: String, allColumns: String, values: IndexedSeq[DbValue], conflictColumn: String): Frag

Overload accepting comma-joined column string (as Repo does).

Overload accepting comma-joined column string (as Repo does).

Attributes

Source
Upsert.scala
def doNothingSuffix(conflictColumn: String): Frag

Suffix ON CONFLICT ("col") DO NOTHING.

Suffix ON CONFLICT ("col") DO NOTHING.

Attributes

Source
Upsert.scala
def doUpdate(tableName: String, columns: IndexedSeq[String], values: IndexedSeq[DbValue], conflictColumn: String, assignments: IndexedSeq[(String, DbValue)]): Frag

Low-level builder: full INSERT with DO UPDATE SET.

Low-level builder: full INSERT with DO UPDATE SET.

Attributes

Source
Upsert.scala
def doUpdateSuffix(conflictColumn: String, assignments: IndexedSeq[(String, DbValue)]): Frag

Suffix ON CONFLICT ("conflict") DO UPDATE SET "col" = ?, .... Assignments must be non-empty; each column is validated and quoted.

Suffix ON CONFLICT ("conflict") DO UPDATE SET "col" = ?, .... Assignments must be non-empty; each column is validated and quoted.

Attributes

Source
Upsert.scala
def insertDoNothing[A](table: Table[A], entity: A, conflictColumn: String): Frag

INSERT ... ON CONFLICT ("conflict") DO NOTHING for an entity.

INSERT ... ON CONFLICT ("conflict") DO NOTHING for an entity.

Builds INSERT INTO "table" ("cols") VALUES (?, ...) ON CONFLICT ("conflict") DO NOTHING. The table name is validated via SqlIdentifier.validate and the conflict column is validated as an identifier and checked for membership in table.columns.

Value parameters

conflictColumn

validated identifier that must be present in table.columns

entity

entity whose values are obtained via table.codec.toDbValues

table

validated via Table; its name via SqlIdentifier.validate and its columns used for conflict validation

Attributes

Returns

a Frag whose SQL is INSERT ... ON CONFLICT ("conflict") DO NOTHING with a quoted INSERT INTO "table" ("cols") head

Throws
IllegalArgumentException

if conflictColumn is not a valid identifier or is not found in table.columns

Source
Upsert.scala
def insertDoUpdate[A](table: Table[A], entity: A, conflictColumn: String): Frag

INSERT ... ON CONFLICT ("conflict") DO UPDATE SET ... for an entity.

INSERT ... ON CONFLICT ("conflict") DO UPDATE SET ... for an entity.

Updates all columns except the conflict column. The conflict column is validated via SqlIdentifier.validate and must exist in table.columns. The update set is derived as table.columns.filter(_ != conflict) and validated against Table.columns.

Value parameters

conflictColumn

validated identifier that must be present in table.columns

entity

entity serialized via table.codec.toDbValues

table

validated via Table; name validated via SqlIdentifier.validate

Attributes

Returns

a Frag with ON CONFLICT ("conflict") DO UPDATE SET "col" = ?, ... where cols are all table columns except the conflict column

Throws
IllegalArgumentException

if conflictColumn is invalid or not in table.columns, or if the table has only the conflict column (no assignable columns to update)

Source
Upsert.scala
def insertDoUpdate[A](table: Table[A], entity: A, conflictColumn: String, updateColumns: Seq[String]): Frag

INSERT ... ON CONFLICT ("conflict") DO UPDATE SET "col" = ?, ... for an entity with explicit update columns.

INSERT ... ON CONFLICT ("conflict") DO UPDATE SET "col" = ?, ... for an entity with explicit update columns.

All identifiers are validated via SqlIdentifier.validate. The conflict column and each updateColumns entry must exist in table.columns.

Value parameters

conflictColumn

validated identifier that must be present in table.columns

entity

entity serialized via table.codec.toDbValues

table

validated via Table; name validated via SqlIdentifier.validate

updateColumns

validated against table.columns; each entry validated as an identifier, must exist in the table, must not contain conflictColumn, and must be non-empty

Attributes

Returns

a Frag with ON CONFLICT ("conflict") DO UPDATE SET for the specified columns

Throws
IllegalArgumentException

if any identifier is invalid, if any column is not in table.columns, if updateColumns contains the conflict column or contains duplicates, or if it is empty

Source
Upsert.scala