跳转到主要内容

ClickHouse Python/asyncio库,与SQLAlchemy核心一起使用

项目描述

ClickHouse Python/asyncio库,与SQLAlchemy核心一起使用

示例

import aiochsa
import sqlalchemy as sa

table = sa.Table(
    'test', sa.MetaData(),
    sa.Column('id', sa.Integer),
    sa.Column('name', sa.String),
)

async with aiochsa.connect('clickhouse://127.0.0.1:8123') as conn:
    await conn.execute(
        table.insert(),
        [
            {'id': 1, 'name': 'Alice'},
            {'id': 2, 'name': 'Bob'},
        ],
    )
    rows = await conn.fetch(
        table.select()
    )

要添加FINAL修饰符,请使用with_hint(table, 'FINAL')(有关详细信息,请参阅SQLAlchemy文档)。

配置日志以显示SQL

logging.getLogger('aiochsa.client.SQL').setLevel(logging.DEBUG)

自定义类型转换器

以下是一个为ClickHouse的DateTime类型安装转换器的示例,该转换器需要并返回Python的datetime对象,并以UTC存储。

from datetime import datetime
import aiochsa
from aiochsa.types import DateTimeUTCType, TypeRegistry

types = TypeRegistry()
types.register(DateTimeUTCType, ['DateTime'], datetime)
conn = aiochsa.connect(dsn, types=types)

变更日志

请参阅变更日志

开发

先决条件:Python(使用pyenv管理多个版本)、pip、tox、coverage、docker、docker-compose。

运行测试

# Run whole tests matrix:
tox
# Run test with specific Python version only:
tox -e py38
# Test with specific Clickhouse version:
tox -e py38 -- --clickhouse-version=21.2.2.8
# Run specified test(s):
tox -e py38 -- tests/test_execute.py::test_aggregate_function

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分发

aiochsa-1.2.2.tar.gz (30.6 kB 查看哈希值)

上传时间

构建版本

aiochsa-1.2.2-py3-none-any.whl (21.4 kB 查看哈希值)

上传时间 Python 3

由以下支持