clickhouse_postgres_client/
lib.rs

1pub use sqlx_clickhouse_ext;
2
3pub mod connect_options;
4pub mod executor;
5pub mod row;
6pub mod type_info;
7pub use self::connect_options::ClickhousePgConnectOptions;
8pub use self::executor::ClickhouseExecutor;
9pub use self::row::ClickhousePgRow;
10pub use self::type_info::ClickhousePgValue;
11
12pub type SqlxError = sqlx_clickhouse_ext::sqlx_core::error::Error;
13pub type ClickhousePgPool = sqlx_clickhouse_ext::sqlx_core::postgres::PgPool;
14pub type ClickhousePgPoolOptions = sqlx_clickhouse_ext::sqlx_core::postgres::PgPoolOptions;
15pub type ClickhousePgPoolConnection = sqlx_clickhouse_ext::sqlx_core::pool::PoolConnection<
16    sqlx_clickhouse_ext::sqlx_core::postgres::Postgres,
17>;
18pub type ClickhousePgConnection = sqlx_clickhouse_ext::sqlx_core::postgres::PgConnection;
19
20//
21use sqlx_clickhouse_ext::sqlx_core::{
22    connection::ConnectOptions as _, database::Database as SqlxDatabase,
23};
24
25pub async fn connect(url: &str) -> Result<ClickhousePgConnection, SqlxError> {
26    connect_with(&url.parse()?).await
27}
28
29pub async fn connect_with(
30    options: &ClickhousePgConnectOptions,
31) -> Result<ClickhousePgConnection, SqlxError> {
32    options.inner.connect().await
33}
34
35pub async fn execute<'c, 'q, 'async_trait, E>(sql: &'q str, executor: E) -> Result<(), SqlxError>
36where
37    E: ClickhouseExecutor<'c, 'q, 'async_trait, ClickhousePgRow>,
38    'c: 'async_trait,
39    'q: 'async_trait,
40    ClickhousePgRow: From<<E::Database as SqlxDatabase>::Row>,
41{
42    ClickhouseExecutor::execute(executor, sql).await
43}
44
45pub async fn fetch_all<'c, 'q, 'async_trait, E>(
46    sql: &'q str,
47    executor: E,
48) -> Result<Vec<ClickhousePgRow>, SqlxError>
49where
50    E: ClickhouseExecutor<'c, 'q, 'async_trait, ClickhousePgRow>,
51    'c: 'async_trait,
52    'q: 'async_trait,
53    ClickhousePgRow: From<<E::Database as SqlxDatabase>::Row>,
54{
55    ClickhouseExecutor::fetch_all(executor, sql).await
56}
57
58pub async fn fetch_one<'c, 'q, 'async_trait, E>(
59    sql: &'q str,
60    executor: E,
61) -> Result<ClickhousePgRow, SqlxError>
62where
63    E: ClickhouseExecutor<'c, 'q, 'async_trait, ClickhousePgRow>,
64    'c: 'async_trait,
65    'q: 'async_trait,
66    ClickhousePgRow: From<<E::Database as SqlxDatabase>::Row>,
67{
68    ClickhouseExecutor::fetch_one(executor, sql).await
69}
70
71pub async fn fetch_optional<'c, 'q, 'async_trait, E>(
72    sql: &'q str,
73    executor: E,
74) -> Result<Option<ClickhousePgRow>, SqlxError>
75where
76    E: ClickhouseExecutor<'c, 'q, 'async_trait, ClickhousePgRow>,
77    'c: 'async_trait,
78    'q: 'async_trait,
79    ClickhousePgRow: From<<E::Database as SqlxDatabase>::Row>,
80{
81    ClickhouseExecutor::fetch_optional(executor, sql).await
82}