Skip to main content

Db

Trait Db 

Source
pub trait Db: Send + Sync {
    // Required methods
    fn dialect(&self) -> Dialect;
    fn all<'a>(
        &'a self,
        sql: &'a str,
        params: Vec<Param>,
    ) -> BoxFuture<'a, Result<Vec<Row>, DbError>>;
    fn run<'a>(
        &'a self,
        sql: &'a str,
        params: Vec<Param>,
    ) -> BoxFuture<'a, Result<u64, DbError>>;
    fn hold(&self, kind: Hold) -> BoxFuture<'_, Result<Arc<dyn Db>, DbError>>;

    // Provided methods
    fn finish(&self, _ok: bool) -> BoxFuture<'_, Result<(), DbError>> { ... }
    fn metered(&self) -> bool { ... }
    fn close(&self) -> BoxFuture<'_, ()> { ... }
    fn prefix(&self) -> Option<&str> { ... }
}
Expand description

The little a store needs from a database driver. SQL uses ? placeholders and “double quotes” around a name that is a keyword somewhere; a driver numbers the placeholders, or fills them in and quotes names its own way, as the TypeScript drivers do.

Required Methods§

Source

fn dialect(&self) -> Dialect

The SQL the database speaks.

Source

fn all<'a>( &'a self, sql: &'a str, params: Vec<Param>, ) -> BoxFuture<'a, Result<Vec<Row>, DbError>>

Runs a query and gives its rows.

Source

fn run<'a>( &'a self, sql: &'a str, params: Vec<Param>, ) -> BoxFuture<'a, Result<u64, DbError>>

Runs a statement and says how many rows it matched.

Source

fn hold(&self, kind: Hold) -> BoxFuture<'_, Result<Arc<dyn Db>, DbError>>

One connection, held for a transaction or a lock until finish. Statements on it run in turn with nothing else of the store’s in between. Holding a transaction on a connection already in one joins it.

Provided Methods§

Source

fn finish(&self, _ok: bool) -> BoxFuture<'_, Result<(), DbError>>

Ends what hold began: commits a transaction (ok) or rolls it back, or lets go of a lock. A connection that was not held answers Ok.

Source

fn metered(&self) -> bool

True for a database reached one statement at a time over the network with a cap on statements per request (Cloudflare D1), so long jobs send fewer, larger pieces.

Source

fn close(&self) -> BoxFuture<'_, ()>

Lets the connections go.

Source

fn prefix(&self) -> Option<&str>

The prefix this Db puts on Runlight’s table and index names in place of rl_, when it puts one (Prefixed), so a store over it keeps it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§