Skip to content

Admin

Admin(client, database=None, cluster=None)

Provides administrative operations for the ClickHouse database.

Parameters:

Name Type Description Default
client Client

The ClickHouse client to use for operations.

required
database str | None

The database to operate on.

None
cluster str | None

The cluster to operate on.

None

add_column(table, column, *, database=None) async

Add a column to a table.

alter_table(table, operations=None, *, database=None, drop_columns=True, add_columns=True, modify_columns=True) async

Alter a table by applying a set of operations.

copy_table(table, *, name, database=None) async

Copy a table to a new table.

create_all(registry=default_registry, *, database=None, if_not_exists=True) async

Create all managed and protected tables and views from the registry.

Parameters:

Name Type Description Default
registry Registry

The registry to create tables and views from.

default_registry
database str | None

The database to create tables and views in.

None
if_not_exists bool

Whether to create tables and views if they already exist.

True

create_datbase(name, *, if_not_exists=True, cluster=None, engine=None, settings=None, comment=None) async

Create a new database.

create_materialized_view(view, table, *, if_not_exists=True, database=None) async

Create a new materialized view.

create_model(query, name) async

Create a Pydantic model for the result of a given query

create_simple_view(view, *, replace=True, database=None) async

Create a new simple view.

create_table(table, *, if_not_exists=True, database=None, cluster=None, engine=None) async

Create a new table.

create_view(view, *, if_not_exists=True, replace=True, database=None) async

Create a new view.

diff_table(table, *, database=None) async

Compare a local table with a table in the database and return the differences.

drop_all(registry=default_registry, *, database=None, if_exists=True) async

Drop all managed tables and views from the registry.

Parameters:

Name Type Description Default
registry Registry

The registry to drop tables and views from.

default_registry
database str | None

The database to drop tables and views from.

None
if_exists bool

Whether to drop tables and views if they do not exist.

True

drop_column(table, column, *, database=None) async

Drop a column from a table.

drop_datbase(name, *, if_exists=True, cluster=None, sync=False) async

Drop a database.

drop_table(table, *, if_exists=True, if_empty=False, database=None, cluster=None, sync=False, force=False) async

Drop a table.

drop_view(view, *, if_exists=True, database=None, cluster=None, sync=False, force=False) async

Drop a view.

get_table(name, *, database=None) async

Get a table by name.

get_view(name, *, database=None) async

Get a view by name.

migrate_all(registry=default_registry, *, database=None, create_all=True, force=False) async

Migrate all managed tables and views from the registry.

Parameters:

Name Type Description Default
registry Registry

The registry to migrate tables and views from.

default_registry
database str | None

The database to migrate tables and views to.

None
force bool

Whether to force the migration even if the table or view is not managed.

False

migrate_table(table, *, database=None, force=False) async

Migrate a table to the latest schema.

Parameters:

Name Type Description Default
table Table

The table to migrate.

required
database str | None

The database to migrate the table to.

None
force bool

Whether to force the migration even if the table is not managed.

False

migrate_view(view, *, database=None, force=False) async

Migrate a view to the latest schema.

Parameters:

Name Type Description Default
view View

The view to migrate.

required
database str | None

The database to migrate the view to.

None
force bool

Whether to force the migration even if the view is not managed.

False

modify_column(table, column, *, database=None) async

Modify a column in a table.

show_create_table(name, *, database=None) async

Show the create table statement for a given table.

show_databases() async

Show all databases

show_tables(*, database=None) async

Show all tables in the database.

show_views(*, database=None) async

Show all views in the database.

truncate_table(table, *, database=None) async

Truncate a table.