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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! Async SQL access for mariadb, mysql, postgres, and sqlite.
//!
//! `quex` is a small facade over [`quex_driver`]. It gives you one API for:
//!
//! - opening one connection or a pool
//! - running SQL directly
//! - binding positional parameters
//! - decoding rows into your own types
//!
//! It stays close to SQL. This crate does not try to hide queries behind an
//! orm or query builder.
//!
//! The main entry points are:
//!
//! - [`Pool`] for many short-lived checked-out connections
//! - [`Connection`] for one connection
//! - [`query`] for one-off SQL
//! - [`prepare`] for a reusable prepared statement
//! - [`Hooks`] when a pool needs connection setup or validation
//! - [`Executor`] when you want generic code that works with any supported
//! executor type
//! - [`Encode`] for binding your own parameter types
//! - [`FromRow`], [`FromRowRef`], and [`Decode`] for mapping rows into your own
//! types
//!
//! `query` and `prepare` use `?` placeholders for every driver. When the driver
//! is postgres, `quex` rewrites them to `$1`, `$2`, and so on before sending
//! the SQL to libpq.
//!
//! A small sqlite example:
//!
//! ```no_run
//! use quex::{FromRow, Pool, Row, SqliteConnectOptions};
//!
//! struct User {
//! id: i64,
//! name: String,
//! }
//!
//! impl FromRow for User {
//! fn from_row(row: &Row) -> quex::Result<Self> {
//! Ok(Self {
//! id: row.get("id")?,
//! name: row.get("name")?,
//! })
//! }
//! }
//!
//! # async fn run() -> quex::Result<()> {
//! let pool = Pool::connect(SqliteConnectOptions::new().in_memory())?
//! .max_size(4)
//! .build()
//! .await?;
//! let mut db = pool.acquire().await?;
//!
//! quex::query("create table users(id integer primary key, name text not null)")
//! .execute(&mut db)
//! .await?;
//!
//! quex::query("insert into users(name) values(?)")
//! .bind("Ada")
//! .execute(&mut db)
//! .await?;
//!
//! let users = quex::query("select id, name from users order by id")
//! .all::<User>(&mut db)
//! .await?;
//! # let _ = users;
//! # Ok(())
//! # }
//! ```
//!
//! When you already have a [`Pool`], the high-level query helpers can run
//! directly against it:
//!
//! ```no_run
//! # use quex::{Pool, SqliteConnectOptions};
//! # async fn run() -> quex::Result<()> {
//! let pool = Pool::connect(SqliteConnectOptions::new().in_memory())?
//! .max_size(4)
//! .build()
//! .await?;
//!
//! let ids: Vec<i64> = quex::query("select id from users order by id")
//! .all(&pool)
//! .await?;
//! # let _ = ids;
//! # Ok(())
//! # }
//! ```
//!
//! A few things matter when using the crate:
//!
//! - Borrowed rows only live until the stream advances. If you need to keep
//! data longer, decode into owned types or collect owned rows.
//! - [`Query::one`] and [`Query::optional`] ignore extra rows.
//! - A [`PoolTransaction`] holds one checked-out connection until commit,
//! rollback, or drop.
//! - [`Pool::with_hooks`] can run setup on fresh connections and validate a
//! connection before it is handed out.
//! - [`Pool`] is the better default when many tasks need database access.
//! [`Connection`] is the simpler single-connection option.
//! - Postgres `LISTEN`/`NOTIFY` works on [`Connection`] and
//! [`PooledConnection`]. Keep one checked-out connection dedicated to waiting
//! for notifications.
//!
//! Optional features add support for common value types:
//!
//! - `mysql` enables mysql and mariadb support
//! - `postgres` enables postgres support
//! - `sqlite` enables sqlite support
//! - `chrono` for chrono date and time types
//! - `time` for `time` crate types
//! - `uuid` for `uuid::Uuid`
//! - `json` for `serde_json::Value`
//!
//! Setup depends on the driver you use. `quex_driver` talks to libpq,
//! libmariadb, and sqlite3 through ffi, so those client libraries need to be
//! available for your target environment. No database backend is enabled by
//! default, so pick the ones you need in your `Cargo.toml`.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Notification as PostgresNotification;
pub use ;
pub use Statement;