QuackDB.DDL (quackdb v0.3.0)

Copy Markdown View Source

Small DuckDB DDL SQL builders.

These helpers return SQL iodata for common analytical setup tasks such as temporary tables in tests or notebooks. They are not an Ecto migration layer; execute the generated SQL with QuackDB.query/4 or Repo.query/3.

QuackDB.DDL.create_table("events",
  [
    id: :integer,
    name: :varchar,
    payload: :json,
    occurred_at: :timestamp
  ],
  temporary: true,
  if_not_exists: true
)

Summary

Functions

Builds a CREATE TABLE statement from an Ecto schema module.

Builds a CREATE TABLE statement.

Builds a CREATE TABLE AS statement.

Builds a DROP TABLE statement.

Types

column()

@type column() ::
  {atom() | String.t(), column_type()}
  | {atom() | String.t(), column_type(), keyword()}

column_type()

@type column_type() :: QuackDB.Type.spec()

create_table_option()

@type create_table_option() ::
  {:temporary, boolean()} | {:if_not_exists, boolean()} | {:as, iodata()}

Functions

create_table(schema)

@spec create_table(module()) :: iodata()

Builds a CREATE TABLE statement from an Ecto schema module.

create_table(schema_or_name, options_or_columns)

@spec create_table(
  module() | String.t() | atom(),
  [create_table_option()] | [column()]
) :: iodata()

create_table(name, columns, options \\ [])

@spec create_table(String.t() | atom(), [column()], [create_table_option()]) ::
  iodata()

Builds a CREATE TABLE statement.

QuackDB.DDL.create_table("events", id: :integer, name: :varchar)
QuackDB.DDL.create_table("events", [id: :integer], temporary: true)

Pass :as to build CREATE TABLE AS from iodata or an Ecto query without pinned params:

QuackDB.DDL.create_table("docs", as: query, temporary: true)

create_table_as(name, query, options \\ [])

@spec create_table_as(String.t() | atom(), iodata(), [create_table_option()]) ::
  iodata()

Builds a CREATE TABLE AS statement.

drop_table(name, options \\ [])

@spec drop_table(
  String.t() | atom(),
  keyword()
) :: iodata()

Builds a DROP TABLE statement.