Skip to main content

omnia_wasi_sql/host/
resource.rs

1use std::fmt::Debug;
2use std::ops::Deref;
3use std::sync::Arc;
4
5pub use omnia::FutureResult;
6
7use crate::host::{DataType, Row};
8
9/// SQL providers implement the [`Connection`] trait to allow the host to
10/// connect to a backend (Azure Table Storage, Postgres, etc) and execute SQL
11/// statements.
12pub trait Connection: Debug + Send + Sync + 'static {
13    /// Execute a query and return the resulting rows.
14    fn query(&self, query: String, params: Vec<DataType>) -> FutureResult<Vec<Row>>;
15
16    /// Execute a query that does not return rows (e.g., an `INSERT`, `UPDATE`, or `DELETE`).
17    fn exec(&self, query: String, params: Vec<DataType>) -> FutureResult<u32>;
18}
19
20/// [`ConnectionProxy`] provides a concrete wrapper around a `dyn Connection` object.
21/// It is used to store connection resources in the resource table.
22#[derive(Clone, Debug)]
23pub struct ConnectionProxy(pub Arc<dyn Connection>);
24
25impl Deref for ConnectionProxy {
26    type Target = Arc<dyn Connection>;
27
28    fn deref(&self) -> &Self::Target {
29        &self.0
30    }
31}
32
33/// Represents a statement resource in the WASI SQL host.
34#[derive(Clone, Debug)]
35pub struct Statement {
36    /// SQL query string.
37    pub query: String,
38
39    /// Query parameters.
40    pub params: Vec<DataType>,
41}