sparkling/schema

Types

A field (column) definition in a ClickHouse table.

pub type Field {
  Field(name: String, typ: FieldType)
}

Constructors

ClickHouse field types supported by sparkling. Examples: docs/examples/schema_examples.md

pub type FieldType {
  UInt8
  UInt16
  UInt32
  UInt64
  Int8
  Int16
  Int32
  Int64
  Float32
  Float64
  String
  FixedString(size: Int)
  Date
  Date32
  DateTime
  DateTime64(precision: Int)
  Decimal(precision: Int, scale: Int)
  Bool
  UUID
  Nullable(of: FieldType)
  Array(of: FieldType)
  LowCardinality(of: FieldType)
  JSON
  Tuple(fields: List(FieldType))
  Enum8(values: List(#(String, Int)))
  Enum16(values: List(#(String, Int)))
}

Constructors

  • UInt8
  • UInt16
  • UInt32
  • UInt64
  • Int8
  • Int16
  • Int32
  • Int64
  • Float32
  • Float64
  • String
  • FixedString(size: Int)
  • Date
  • Date32
  • DateTime
  • DateTime64(precision: Int)
  • Decimal(precision: Int, scale: Int)
  • Bool
  • UUID
  • Nullable(of: FieldType)
  • Array(of: FieldType)
  • LowCardinality(of: FieldType)
  • JSON
  • Tuple(fields: List(FieldType))
  • Enum8(values: List(#(String, Int)))
  • Enum16(values: List(#(String, Int)))

A table definition with name and fields.

pub type Table {
  Table(name: String, fields: List(Field))
}

Constructors

  • Table(name: String, fields: List(Field))

Values

pub fn field(name: String, typ: FieldType) -> Field

Create a new field definition. Examples: docs/examples/schema_examples.md

pub fn field_names(tbl: Table) -> List(String)

Get all field names from a table. Examples: docs/examples/schema_examples.md

pub fn field_type_to_sql(typ: FieldType) -> String

Get the SQL representation of a field type for CREATE TABLE DDL. Examples: docs/examples/schema_examples.md

pub fn find_field(
  tbl: Table,
  field_name: String,
) -> option.Option(Field)

Find a field in a table by name. Examples: docs/examples/schema_examples.md

pub fn table(name: String, fields: List(Field)) -> Table

Create a new table definition. Examples: docs/examples/schema_examples.md

pub fn to_create_table_sql(
  tbl: Table,
  engine engine: String,
) -> String

Generate a CREATE TABLE statement for a table definition.

Note: This is a minimal DDL generator. For production use, specify engine, partition key, order by, etc., using ClickHouse-specific syntax. Examples: docs/examples/schema_examples.md

Search Document