QuackDB.Sequence (quackdb v0.5.3)

Copy Markdown View Source

Helpers for DuckDB sequences.

Native append writes full column vectors and does not evaluate column defaults. Use next_values/4 to allocate sequence-backed IDs before appending rows with explicit primary keys.

Summary

Functions

Returns the sequence backing a table column default.

Returns the sequence backing a table column default, raising on errors.

Returns count values from a DuckDB sequence.

Functions

for_column(connection, source, column, options \\ [])

@spec for_column(
  DBConnection.conn() | module(),
  QuackDB.Meta.source(),
  atom() | String.t(),
  Keyword.t()
) :: {:ok, String.t()} | {:error, Exception.t()}

Returns the sequence backing a table column default.

This inspects pragma_table_info and returns the sequence referenced by a nextval('...') default.

for_column!(connection, source, column, options \\ [])

@spec for_column!(
  DBConnection.conn() | module(),
  QuackDB.Meta.source(),
  atom() | String.t(),
  Keyword.t()
) :: String.t()

Returns the sequence backing a table column default, raising on errors.

next_values(connection, sequence_name, count, options \\ [])

@spec next_values(
  DBConnection.conn(),
  atom() | String.t(),
  non_neg_integer(),
  Keyword.t()
) :: [
  integer()
]

Returns count values from a DuckDB sequence.

ids = QuackDB.Sequence.next_values(conn, "fragments_id_seq", 3)
#=> [1, 2, 3]

The sequence name is encoded as a SQL string literal for nextval/1; callers should pass the actual DuckDB sequence name, not raw SQL.