1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Autumn plugin for ClickHouse.
//!
//! Add [`ClickHousePlugin`] to the app. Then use the [`ClickHouse`] extractor in a handler.
//! ClickHouse is the OLAP/analytics counterpart to the `DuckDB` plugin: it queries a remote
//! ClickHouse server over HTTP instead of an embedded database.
//!
//! ```rust,no_run
//! use autumn_plugin_clickhouse::{ClickHouse, ClickHousePlugin, ClickHouseResultExt as _};
//! use autumn_web::prelude::*;
//!
//! #[derive(clickhouse::Row, serde::Serialize, serde::Deserialize)]
//! struct EventCount {
//! name: String,
//! count: u64,
//! }
//!
//! #[get("/events/counts")]
//! async fn event_counts(db: ClickHouse) -> AutumnResult<Json<Vec<EventCount>>> {
//! let rows = db
//! .fetch_all::<EventCount>("SELECT name, count() AS count FROM events GROUP BY name")
//! .await
//! .or_http()?;
//! Ok(Json(rows))
//! }
//!
//! # async fn run() {
//! autumn_web::app()
//! .plugin(ClickHousePlugin::new().configure(|c| {
//! c.url = "http://localhost:8123".into();
//! c.database = "analytics".into();
//! }))
//! .routes(routes![event_counts])
//! .run()
//! .await;
//! # }
//! ```
//!
//! The plugin reads `[clickhouse]` in `autumn.toml`. See [`config`] for the keys.
//!
//! # What the plugin gives
//!
//! - [`ClickHouse`]: typed `SELECT` queries with `#[derive(clickhouse::Row)]` structs,
//! one-batch [`ClickHouse::insert`] and the batching [`Inserter`],
//! plus [`ClickHouse::execute`] for DDL.
//! - [`migrate`]: runs ordered `CREATE TABLE IF NOT EXISTS` migrations at startup.
//! - A `HealthOnly` readiness check that runs `SELECT 1`, and Prometheus call counters.
//!
//! # Limits
//!
//! - Each call has the `timeout_ms` timeout. A timed-out call gives [`ClickHouseError::Timeout`].
//! - Rows must be owned structs: `#[derive(clickhouse::Row, serde::Serialize, serde::Deserialize)]`
//! without lifetimes.
//! - Logs, error text and `Debug` output do not have row data, server messages or passwords.
//! - The plugin needs a reachable ClickHouse server. The startup ping stops the boot if the
//! server is down. Tests use the `clickhouse` mock server, not a live server.
/// The `clickhouse` crate that the plugin uses. Use it for the `Row` derive.
pub use clickhouse;
pub use ;
pub use ;
pub use ;
pub use Metrics;
pub use ;
pub use ;