Skip to content

Table

Table(model, *, name=None, engine=None, columns=None, comment=None, lifecycle=Lifecycle.managed, registry=default_registry)

Create a new table from a Pydantic model.

Parameters:

Name Type Description Default
model type[T]

The Pydantic model to create the table from.

required
name str | None

The name of the table. Defaults to the snake_case version of the model name.

None
engine Engine | str | None

The engine to use for the table. Defaults to MergeTree().

None
columns dict[str, Column] | None

The columns to use for the table. Defaults to the columns defined in the model.

None
comment str | None

The comment to use for the table. Defaults to None.

None
lifecycle Lifecycle

The lifecycle to use for the table. Defaults to Lifecycle.managed.

managed
registry Registry

The registry to use for the table. Defaults to the global registry.

default_registry

from_sql(name, columns, engine) classmethod

Create a new table from a SQL table definition.

A dynamic pydantic model is created based on the columns.

Parameters:

Name Type Description Default
name str

The name of the table.

required
columns list[dict[str, str]]

The columns of the table.

required
engine str

The engine to use for the table.

required

Returns:

Type Description
Self

A new Table instance.

get_model()

Get the model associated with this table.

get_name()

Get the name of this table.

get_engine()

Get the engine of this table.

get_columns()

Get the columns of this table.

get_lifecycle()

Get the lifecycle of this table.