pub trait Connection:
Send
+ Sync
+ 'static {
// Required methods
fn dialect(&self) -> Dialect;
fn fetch<'a>(
&'a self,
route: ShardRoute,
sql: &'a str,
params: Vec<Value>,
columns: Vec<ColumnRequest>,
) -> BoxFuture<'a, Result<Vec<OwnedRow>>>;
fn execute<'a>(
&'a self,
route: ShardRoute,
sql: &'a str,
params: Vec<Value>,
) -> BoxFuture<'a, Result<Vec<ExecOutcome>>>;
fn fetch_raw<'a>(
&'a self,
route: ShardRoute,
sql: &'a str,
params: Vec<Value>,
) -> BoxFuture<'a, Result<Vec<Box<dyn Row>>>>;
// Provided methods
fn shard_family(&self) -> Option<String> { ... }
fn allocate_id(&self, shard_key: u64) -> Option<u64> { ... }
}Expand description
A dyn-safe database backend.
Implemented for concrete Rainier ORM executors by
bind_executor!.
Required Methods§
Sourcefn fetch<'a>(
&'a self,
route: ShardRoute,
sql: &'a str,
params: Vec<Value>,
columns: Vec<ColumnRequest>,
) -> BoxFuture<'a, Result<Vec<OwnedRow>>>
fn fetch<'a>( &'a self, route: ShardRoute, sql: &'a str, params: Vec<Value>, columns: Vec<ColumnRequest>, ) -> BoxFuture<'a, Result<Vec<OwnedRow>>>
Run a query, copying the named columns out of each row.
Send, which is what makes it usable from a request handler.
Sourcefn execute<'a>(
&'a self,
route: ShardRoute,
sql: &'a str,
params: Vec<Value>,
) -> BoxFuture<'a, Result<Vec<ExecOutcome>>>
fn execute<'a>( &'a self, route: ShardRoute, sql: &'a str, params: Vec<Value>, ) -> BoxFuture<'a, Result<Vec<ExecOutcome>>>
Run a write and report its outcome. Send.
Sourcefn fetch_raw<'a>(
&'a self,
route: ShardRoute,
sql: &'a str,
params: Vec<Value>,
) -> BoxFuture<'a, Result<Vec<Box<dyn Row>>>>
fn fetch_raw<'a>( &'a self, route: ShardRoute, sql: &'a str, params: Vec<Value>, ) -> BoxFuture<'a, Result<Vec<Box<dyn Row>>>>
Run a query and hand back the driver’s own rows.
The future is Send even though Vec<Box<dyn Row>> is not — a future’s
output need not be Send for the future to be, because the value is
moved out on the final poll rather than held across a suspension. That
is what lets Database’s Executor impl, and therefore Rainier ORM’
own repo:: API, be used from a request handler.
The rows themselves still cannot cross a thread, so decode them before
the next await — which is exactly what Entity::from_row does.
Provided Methods§
Sourcefn shard_family(&self) -> Option<String>
fn shard_family(&self) -> Option<String>
The shard family this connector routes within, or None for a single
database.
Sourcefn allocate_id(&self, shard_key: u64) -> Option<u64>
fn allocate_id(&self, shard_key: u64) -> Option<u64>
Mint a shard-encoded primary key for a row owned by shard_key.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".