QuackDB.DML (quackdb v0.5.12)

Copy Markdown View Source

Small DuckDB DML SQL builders.

These helpers return SQL iodata for setup and example insert statements while still allowing DuckDB expressions where needed. For large batches, prefer QuackDB.insert_rows/4, QuackDB.insert_columns/4, or QuackDB.Explorer.insert_dataframe/4.

Summary

Functions

Builds a parameterized DELETE FROM ... WHERE ... statement.

Builds an INSERT INTO ... VALUES ... statement.

Builds an INSERT INTO ... SELECT ... FROM ... statement.

Builds a MERGE INTO ... USING ... statement.

Types

merge_insert()

@type merge_insert() :: {:insert, [atom() | String.t()]}

row()

@type row() :: keyword(value()) | %{required(atom() | String.t()) => value()}

table()

@type table() ::
  atom() | String.t() | {atom() | String.t() | nil, atom() | String.t()}

value()

@type value() :: QuackDB.SQL.parameter() | {:expr, iodata()}

where()

@type where() :: keyword(value())

Functions

delete_from(table, options)

@spec delete_from(
  table(),
  keyword()
) :: {iodata(), [QuackDB.SQL.parameter()]}

Builds a parameterized DELETE FROM ... WHERE ... statement.

{sql, params} =
  QuackDB.DML.delete_from(:events,
    where: [event_type: "session_entry", session_file: session_file]
  )

QuackDB.query!(conn, sql, params)

nil values generate IS NULL predicates. {:expr, sql} values are emitted directly for cases where a DuckDB expression is required.

insert_into(table, rows)

@spec insert_into(String.t() | atom(), [row()] | row()) :: iodata()

Builds an INSERT INTO ... VALUES ... statement.

insert_into_select(table, columns, source, select_columns, options \\ [])

@spec insert_into_select(
  table(),
  [atom() | String.t()],
  table(),
  [atom() | String.t()],
  keyword()
) ::
  iodata()

Builds an INSERT INTO ... SELECT ... FROM ... statement.

merge_into(target, options)

@spec merge_into(
  table(),
  keyword()
) :: iodata()

Builds a MERGE INTO ... USING ... statement.