Skip to main content

D1Executor

Trait D1Executor 

Source
pub trait D1Executor: Send + Sync {
    // Required methods
    fn execute(&self, sql: &str, params: &[Value]) -> Result<u64, String>;
    fn query(&self, sql: &str, params: &[Value]) -> Result<Vec<Value>, String>;

    // Provided method
    fn query_one(
        &self,
        sql: &str,
        params: &[Value],
    ) -> Result<Option<Value>, String> { ... }
}
Expand description

Executes prepared SQL statements against D1.

Implementations bridge synchronous DataStore calls to D1’s async API by blocking in the Workers request context (which is single-threaded).

Required Methods§

Source

fn execute(&self, sql: &str, params: &[Value]) -> Result<u64, String>

Execute a statement that doesn’t return rows. Returns affected row count.

Source

fn query(&self, sql: &str, params: &[Value]) -> Result<Vec<Value>, String>

Execute a query and return all matching rows as JSON objects.

Provided Methods§

Source

fn query_one( &self, sql: &str, params: &[Value], ) -> Result<Option<Value>, String>

Execute a query expecting at most one row.

Implementors§