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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// Copyright (c) 2026, Salesforce, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Pure Rust API for Hyper database.
//!
//! This crate provides a safe, idiomatic Rust interface for working with
//! Hyper database files (.hyper). It is a pure-Rust implementation using
//! the `PostgreSQL` wire protocol with Hyper-specific extensions.
//!
//! # Architecture
//!
//! This is a layered API built from four crates:
//! - `hyper-types` — Type definitions with `LittleEndian` encoding
//! - `hyper-protocol` — Wire protocol with `HyperBinary` COPY support
//! - `hyper-client` — Sync/async TCP and gRPC clients
//! - `hyperdb-api` — High-level API (this crate)
//!
//! Optional companion crates:
//! - `sea-query-hyper` — `HyperDB` SQL dialect backend for `sea-query`
//! - `hyperdb-api-salesforce` — Salesforce Data Cloud OAuth authentication
//!
//! # Quick Start
//!
//! ```no_run
//! use hyperdb_api::{HyperProcess, Connection, CreateMode, Result};
//!
//! fn main() -> Result<()> {
//! let hyper = HyperProcess::new(None, None)?;
//! let conn = Connection::new(&hyper, "example.hyper", CreateMode::CreateIfNotExists)?;
//!
//! conn.execute_command("CREATE TABLE test (id INT, name TEXT)")?;
//! conn.execute_command("INSERT INTO test VALUES (1, 'Hello')")?;
//!
//! let mut result = conn.execute_query("SELECT * FROM test")?;
//! while let Some(chunk) = result.next_chunk()? {
//! for row in &chunk {
//! let id: Option<i32> = row.get(0);
//! let name: Option<String> = row.get(1);
//! println!("id: {:?}, name: {:?}", id, name);
//! }
//! }
//! Ok(())
//! }
//! ```
//!
//! # Lifetime Safety
//!
//! The API uses lifetime annotations to provide compile-time guarantees that
//! resources are used correctly. All dependent types ([`Inserter`],
//! [`Catalog`], [`Rowset`], [`Transaction`]) carry a `'conn` lifetime
//! parameter tying them to the [`Connection`] they borrow:
//!
//! ```text
//! Connection (owns underlying client)
//! ├── Inserter<'conn>
//! │ └── CopyInWriter<'conn>
//! ├── Catalog<'conn>
//! ├── Rowset<'conn>
//! └── Transaction<'conn>
//! ```
//!
//! This is a **simple hierarchical design**, not a complex lifetime web:
//! - **Single root owner**: `Connection` owns the underlying client
//! - **Simple borrows**: All dependent types borrow `&'conn Connection`
//! - **No circular references**: `Inserter` doesn't reference `Catalog`, etc.
//! - **Single lifetime parameter**: Just one `'conn` — no multi-lifetime bounds
//!
//! The Rust borrow checker enforces that you cannot drop or move a `Connection`
//! while any dependent type holds a reference to it:
//!
//! ```compile_fail
//! # use hyperdb_api::{Connection, Inserter, CreateMode};
//! # fn example() -> hyperdb_api::Result<()> {
//! let conn = Connection::connect("localhost:7483", "test.hyper", CreateMode::CreateIfNotExists)?;
//! let inserter = Inserter::new(&conn, /* ... */)?;
//! drop(conn); // ERROR: cannot move `conn` because it is borrowed by `inserter`
//! # Ok(())
//! # }
//! ```
//!
//! The `execute(self)` method on [`Inserter`] takes ownership (`self`), which
//! automatically ends the borrow when the insert completes — no manual cleanup
//! needed.
//!
//! # Key Types
//!
//! - [`Connection`] / [`AsyncConnection`] — Sync and async database connections
//! - [`HyperProcess`] — Manage a local `hyperd` server process
//! - [`Inserter`] / [`MappedInserter`] / [`AsyncInserter`] — Bulk row insertion (`HyperBinary` COPY)
//! - [`ArrowInserter`] / [`AsyncArrowInserter`] — Arrow `RecordBatch` insertion
//! - [`Catalog`] — Schema/table introspection
//! - [`TableDefinition`] — Define table schemas
//! - [`Transaction`] / [`AsyncTransaction`] — RAII transaction guards
//!
//! # Public Modules
//!
//! - [`copy`] — CSV/text export and import via COPY protocol
//! - [`pool`] — Async connection pooling (deadpool-based)
//! - [`grpc`] — gRPC transport types for Arrow IPC queries
//!
//! # Bulk Data Loading
//!
//! Several inserter APIs are available depending on your data format and runtime model:
//! - [`Inserter`] / [`MappedInserter`] — Sync `HyperBinary` row-by-row
//! - [`AsyncInserter`] — Async `HyperBinary` row-by-row (mirrors [`Inserter`])
//! - [`ArrowInserter`] — Sync Arrow IPC (batch or streaming `RecordBatch`)
//! - [`AsyncArrowInserter`] — Async Arrow IPC
//! - [`copy`] module — CSV/TSV/delimited text import & export
//!
//! # Authentication
//!
//! The client supports multiple authentication methods (Trust, Cleartext, MD5, SCRAM-SHA-256):
//!
//! ```no_run
//! use hyperdb_api::{Connection, CreateMode, Result};
//!
//! fn main() -> Result<()> {
//! let conn = Connection::connect_with_auth(
//! "localhost:7483",
//! "example.hyper",
//! CreateMode::CreateIfNotExists,
//! "myuser",
//! "mypassword",
//! )?;
//! Ok(())
//! }
//! ```
/// Semantic version of this crate, resolved at compile time from
/// `Cargo.toml`. Used by downstream tools (notably `hyperdb-mcp`) to
/// surface the library version in their own status output without
/// duplicating the version string.
pub const VERSION: &str = env!;
/// CSV/text export and import via COPY protocol.
/// Connection pooling support.
pub
pub use ArrowInserter;
pub use ArrowReader;
pub use ;
pub use ;
pub use AsyncConnection;
pub use AsyncConnectionBuilder;
pub use AsyncInserter;
pub use ;
pub use AsyncRowset;
pub use Catalog;
pub use ;
pub use ConnectionBuilder;
pub use ;
pub use ToSqlParam;
pub use PreparedStatement;
// Re-export ErrorKind for matching on error categories, and Notice for callbacks
pub use AsyncTransaction;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ServerVersion;
pub use ;
pub use Transaction;
// Re-export types from hyperdb-api-core's types layer.
pub use ;
/// Re-export of `GeoError` from hyperdb-api-core::types.
pub use GeoError;
/// Re-export of the PostgreSQL OID constants. Access as `hyperdb_api::oids::INT4` etc.
pub use oids;
// Re-export gRPC types (always available)
/// Macro for creating table definitions with a fluent syntax.
///
/// This macro simplifies the common pattern of creating table definitions
/// with multiple columns by providing a more compact syntax.
///
/// # Syntax
///
/// ```text
/// table! {
/// "table_name" {
/// "column_name": SqlType::type_name(), NULLABLE | NOT_NULL,
/// // ... more columns
/// }
/// }
/// ```
///
/// # Example
///
/// ```no_run
/// # use hyperdb_api::{table, TableDefinition, SqlType, Result};
/// # fn example() -> Result<()> {
/// let orders = table! {
/// "Orders" {
/// "Address ID": SqlType::small_int(), NOT_NULL,
/// "Customer ID": SqlType::text(), NOT_NULL,
/// "Order Date": SqlType::date(), NOT_NULL,
/// "Order ID": SqlType::text(), NOT_NULL,
/// "Ship Date": SqlType::date(), NULLABLE,
/// "Ship Mode": SqlType::text(), NULLABLE,
/// }
/// };
///
/// // Equivalent to:
/// let orders_manual = TableDefinition::new("Orders")
/// .add_required_column("Address ID", SqlType::small_int())
/// .add_required_column("Customer ID", SqlType::text())
/// .add_required_column("Order Date", SqlType::date())
/// .add_required_column("Order ID", SqlType::text())
/// .add_nullable_column("Ship Date", SqlType::date())
/// .add_nullable_column("Ship Mode", SqlType::text());
/// # Ok(())
/// # }
/// ```