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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//! Compile-time checked PostgreSQL queries with binary-format performance.
//!
//! resolute validates SQL against a live database at compile time (or offline
//! via cached metadata), generates typed result structs, and executes queries
//! using PostgreSQL's binary wire format for zero-overhead type mapping.
//!
//! # Quick start
//!
//! ```ignore
//! use resolute::{Client, query};
//!
//! let url = std::env::var("DATABASE_URL")?;
//! let client = Client::connect_from_str(&url).await?;
//!
//! // Compile-time checked with positional params:
//! let row = query!("SELECT id, name FROM users WHERE id = $1", user_id)
//! .fetch_one(&client)
//! .await?;
//! println!("{}: {}", row.id, row.name);
//!
//! // Named parameters (unique to resolute, not available in sqlx):
//! let row = query!("SELECT id, name FROM users WHERE id = :id", id = user_id)
//! .fetch_one(&client)
//! .await?;
//! ```
//!
//! # Named parameters
//!
//! Both compile-time macros and runtime methods support `:name` syntax.
//! Named params are rewritten to `$1, $2, ...` before hitting PostgreSQL.
//! Duplicate names reuse the same positional slot. `::` casts, string
//! literals, and comments are handled correctly.
//!
//! ```ignore
//! // Compile-time:
//! query!("SELECT :val::int4 WHERE :val > 0", val = my_var)
//!
//! // Runtime:
//! client.query_named(
//! "SELECT :id::int4 AS n",
//! &[("id", &42i32)],
//! ).await?;
//! ```
//!
//! # Executor trait — generic over connection types
//!
//! Write functions once with `&impl Executor`. Unlike sqlx (which consumes `self`),
//! resolute's Executor uses `&self` — multi-query reuse just works.
//!
//! ```no_run
//! # use resolute::{Client, Executor, TypedError};
//! async fn create_user(db: &impl Executor, name: &str) -> Result<i32, TypedError> {
//! let rows = db.query("INSERT INTO users (name) VALUES ($1) RETURNING id", &[&name.to_string()]).await?;
//! rows[0].get(0)
//! }
//!
//! # async fn _demo() -> Result<(), TypedError> {
//! # let client: Client = unimplemented!();
//! # let txn: resolute::Transaction = unimplemented!();
//! # let pooled: resolute::PooledClient = unimplemented!();
//! create_user(&client, "Alice").await?; // Client
//! create_user(&txn, "Alice").await?; // Transaction
//! create_user(&pooled, "Alice").await?; // Pool
//! # Ok(()) }
//! ```
//!
//! # Context-aware atomicity
//!
//! `db.atomic(|db| ...)` does `BEGIN/COMMIT` on Client, `SAVEPOINT/RELEASE` on
//! Transaction. Same function, correct behavior in any context.
//!
//! ```no_run
//! # use resolute::{Executor, TypedError};
//! async fn transfer(db: &impl Executor, from: i32, to: i32) -> Result<(), TypedError> {
//! db.atomic(|db| Box::pin(async move {
//! db.execute("UPDATE accounts SET balance = balance - 100 WHERE id = $1", &[&from]).await?;
//! db.execute("UPDATE accounts SET balance = balance + 100 WHERE id = $1", &[&to]).await?;
//! Ok(())
//! })).await
//! }
//! ```
//!
//! # Custom PostgreSQL types
//!
//! ```no_run
//! use resolute::{PgComposite, PgDomain, PgEnum};
//!
//! // String-based enum (PostgreSQL CREATE TYPE ... AS ENUM):
//! #[derive(PgEnum)]
//! #[pg_type(rename_all = "snake_case")]
//! enum Mood { Happy, Sad }
//!
//! // Integer-backed enum (stored as int4 in PostgreSQL):
//! #[derive(PgEnum)]
//! #[repr(i32)]
//! enum Status { Active = 1, Inactive = 2, Deleted = 3 }
//!
//! #[derive(PgComposite)]
//! struct Address { street: String, city: String, zip: Option<String> }
//!
//! // Domain type: inherits array OID from inner type.
//! #[derive(PgDomain)]
//! struct Email(String); // ARRAY_OID = 1009 (text[])
//! ```
//!
//! # FromRow derive
//!
//! ```no_run
//! use resolute::FromRow;
//! # use serde::Deserialize;
//! # #[derive(Default, Deserialize)] struct MyStruct;
//! # #[derive(Default)] struct MyStatus;
//! # impl TryFrom<i32> for MyStatus { type Error = String; fn try_from(_: i32) -> Result<Self, Self::Error> { Ok(MyStatus) } }
//! # #[derive(FromRow)] struct Address { street: String }
//!
//! #[derive(FromRow)]
//! struct User {
//! id: i32,
//! #[from_row(rename = "email_address")]
//! email: String,
//! #[from_row(skip)]
//! computed: String, // Default::default()
//! #[from_row(default)]
//! retries: i32, // 0 if missing or NULL
//! #[from_row(json)]
//! metadata: MyStruct, // deserialized from jsonb
//! #[from_row(try_from = "i32")]
//! status: MyStatus, // decoded as i32, then TryFrom
//! #[from_row(flatten)]
//! address: Address, // nested FromRow, shares the row
//! }
//! ```
//!
//! # Query type overrides
//!
//! ```ignore
//! // Override inferred types in query! macros:
//! let row = query!(r#"SELECT id as "id: UserId" FROM users"#)
//! .fetch_one(&client).await?;
//! // row.id is UserId, not i32
//! ```
//!
//! # Performance over sqlx
//!
//! - Binary format: PG sends raw bytes, no text-to-number parsing
//! - Message coalescing: multiple queries batched into one write() syscall
//! - Statement caching: Parse once, Bind+Execute on reuse
//! - Generic array encode/decode for all types via `Vec<T>`
//!
//! # Cargo features
//!
//! - `chrono` (default): `chrono::NaiveDate`, `NaiveTime`, `NaiveDateTime`, `DateTime<Utc>`.
//! - `json` (default): `serde_json::Value` for `json` / `jsonb`.
//! - `uuid` (default): `uuid::Uuid`.
//! - `test-utils` (off by default): exposes the `test_db` module with
//! ephemeral test-database helpers and env-driven connection settings
//! (`RESOLUTE_TEST_ADDR`, `RESOLUTE_TEST_USER`, `RESOLUTE_TEST_PASSWORD`,
//! `RESOLUTE_TEST_DB`). Enabled automatically by the
//! `#[resolute::test]` attribute macro.
pub use BytesMut;
pub use ;
pub use ;
pub use ;
pub use TypedError;
pub use Executor;
pub use ;
pub use ;
pub use TypeOid;
pub use PgType;
pub use RawRow;
pub use CancelToken;
pub use ;
pub use ;
pub use ;
pub use PgRange;
/// Attribute macro for database-backed tests. Auto-creates a temp DB,
/// runs migrations, injects a `Client`, and drops the DB on completion.
pub use test;
/// Derive macro for `FromRow`. Use `#[derive(resolute::FromRow)]` on structs.
pub use FromRow;
/// Derive macro for PostgreSQL composite types.
pub use PgComposite;
/// Derive macro for PostgreSQL domain types (newtypes over a base type).
pub use PgDomain;
/// Derive macro for PostgreSQL enum types.
pub use PgEnum;
/// Compile-time checked query macro. Requires `DATABASE_URL` env var.
pub use query;
/// Compile-time checked query mapped to an existing struct via FromRow.
pub use query_as;
/// Like query! but reads SQL from a file.
pub use query_file;
/// Like query_as! but reads SQL from a file.
pub use query_file_as;
/// Like query_scalar! but reads SQL from a file.
pub use query_file_scalar;
/// Compile-time checked single-scalar query.
pub use query_scalar;
/// Skip compile-time checking (no DATABASE_URL or cache needed).
pub use query_unchecked;
pub use ;
pub use ;
pub use TypeInfo;