dactyl_db/adapter/mod.rs
1//! Adapter trait — internal to dactyl.
2//!
3//! Both `SqliteAdapter` and `NeonAdapter` live behind their respective
4//! feature gates and are reachable as `dactyl::adapter::sqlite::*` /
5//! `dactyl::adapter::neon::*`. Nothing else at the crate root re-exports
6//! the underlying types.
7
8use crate::error::DactylError;
9use crate::rows::{Parameter, Rows};
10use crate::Statement;
11
12/// Internal trait every adapter implements.
13///
14/// Adapters are constructed per call from [`crate::build_adapter`] and dropped
15/// at the end of the call — there is no shared cache, so implementations do
16/// not need to be `Sync` across calls. The trait is kept `Send + Sync` so a
17/// caller could, if it chose to, hold an adapter across awaited points.
18pub trait Adapter: Send + Sync {
19 /// Execute any SQL statement (read or write) and return its rows.
20 ///
21 /// Parameters are bound by the adapter — never interpolated into `query`.
22 fn execute(&self, query: &str, params: &[Parameter]) -> Result<Rows, DactylError>;
23
24 /// Execute a raw schema/DDL/migration operation and return affected rows.
25 fn execute_raw(&self, query: &str, params: &[Parameter]) -> Result<u64, DactylError>;
26
27 /// Execute an atomic batch of statements.
28 fn execute_batch(&self, statements: &[Statement]) -> Result<Vec<Rows>, DactylError>;
29}
30
31#[cfg(feature = "sqlite")]
32pub mod sqlite;
33
34#[cfg(feature = "neon")]
35pub mod neon;