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
//! Autumn plugin for DuckDB.
//!
//! Add [`DuckDbPlugin`] to the app. Then use the [`DuckDb`] extractor in a handler.
//!
//! ```rust,no_run
//! use autumn_plugin_duckdb::{DuckDb, DuckDbPlugin, DuckDbResultExt as _};
//! use autumn_web::prelude::*;
//!
//! #[derive(serde::Deserialize, serde::Serialize)]
//! struct Total {
//! region: String,
//! total: f64,
//! }
//!
//! #[get("/totals/{year}")]
//! async fn totals(db: DuckDb, Path(year): Path<i32>) -> AutumnResult<Json<Vec<Total>>> {
//! let rows = db
//! .query("SELECT region, sum(amount) AS total FROM sales WHERE year = ? GROUP BY region")
//! .bind(year)
//! .fetch_as::<Total>()
//! .await
//! .or_http()?;
//! Ok(Json(rows))
//! }
//!
//! # async fn run() {
//! autumn_web::app()
//! .plugin(DuckDbPlugin::new().setup(|conn| {
//! conn.execute_batch("CREATE TABLE IF NOT EXISTS sales (region TEXT, year INT, amount DOUBLE)")
//! }))
//! .routes(routes![totals])
//! .run()
//! .await;
//! # }
//! ```
//!
//! The plugin reads `[duckdb]` in `autumn.toml`. See [`DuckDbConfig`] for the keys.
//!
//! # Security rules
//!
//! - Bind each value with [`DuckDbQuery::bind`]. Do not put values into the SQL text.
//! - A query has one statement only. The plugin refuses more.
//! - SQL cannot read or write files by default. List the directories in `allowed_directories`.
//! - DuckDB does not download or load extensions by default. Load them in a setup hook.
//! - SQL cannot change the DuckDB configuration after startup.
//! - Each call has a timeout. Each fetch also has a row limit and a byte limit.
//! - The plugin interrupts a timed-out query. Each call gets a new connection, so no session state leaks.
//! - Logs, error text and debug text do not have SQL text, parameter values or DuckDB messages.
pub use ;
pub use ;
pub use DecodeError;
/// The `duckdb` crate that the plugin uses. Use it in setup hooks and in `with_connection`.
pub use duckdb;
pub use ;
pub use Param;
pub use ;
pub use ;