pub struct SqliteConnection { /* private fields */ }Expand description
A Limbo-backed SQLite connection implementing Connection.
Create via SqliteConnection::open (file path) or
SqliteConnection::open_memory (:memory:).
§Statement cache
Each SqliteConnection maintains an LRU cache of compiled limbo::Statement
objects (capacity: STMT_CACHE_CAPACITY = 128). The cache is shared across
clones of the same connection (the clones share the underlying
limbo::Connection) and is updated on every DML/DDL execution. Cache hits
save the per-statement parse-and-compile round-trip inside Limbo.
Implementations§
Source§impl SqliteConnection
impl SqliteConnection
Sourcepub async fn open(path: &str) -> Result<Self, OxiSqlError>
pub async fn open(path: &str) -> Result<Self, OxiSqlError>
Open a Limbo database at the given file path.
Pass ":memory:" for an in-memory database, or use
open_memory for clarity.
§Errors
Returns OxiSqlError if the file cannot be opened or created.
Sourcepub async fn open_memory() -> Result<Self, OxiSqlError>
pub async fn open_memory() -> Result<Self, OxiSqlError>
Open a fresh in-memory Limbo database.
§Errors
Returns OxiSqlError if the engine cannot be initialised.
Sourcepub async fn open_from_bytes(bytes: &[u8]) -> Result<Self, OxiSqlError>
pub async fn open_from_bytes(bytes: &[u8]) -> Result<Self, OxiSqlError>
Open a Limbo-backed connection from an in-memory SQLite database image.
The bytes are copied into an in-memory page store; no temporary file
is ever created, so this works on WASI, in the browser, and on
read-only filesystems. Mirrors SQLite’s sqlite3_deserialize() /
rusqlite’s Connection::deserialize. See
limbo::Database::open_from_bytes.
§Example
use oxisql_core::Connection;
use oxisql_sqlite_compat::SqliteConnection;
// `image` is a complete SQLite database file loaded into memory,
// e.g. `include_bytes!("../data/app.db")`.
let image: &[u8] = get_database_image();
let conn = SqliteConnection::open_from_bytes(image).await?;
let rows = conn.query("SELECT count(*) FROM sqlite_master", &[]).await?;§Errors
Returns OxiSqlError if bytes is not a valid SQLite database image
(too short, wrong magic header, or an invalid page size). Never panics
on malformed input.
Trait Implementations§
Source§impl Clone for SqliteConnection
impl Clone for SqliteConnection
Source§fn clone(&self) -> SqliteConnection
fn clone(&self) -> SqliteConnection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Connection for SqliteConnection
impl Connection for SqliteConnection
Source§fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Source§fn query<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn query<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [&'life3 dyn ToSqlValue],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
SELECT statement and return the result rows. Read moreSource§fn transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Transaction + '_>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Transaction + '_>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn ping<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn ping<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn prepare<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn PreparedStatement + '_>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn prepare<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn PreparedStatement + '_>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn tables<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<TableInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn tables<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<TableInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn columns<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ColumnInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn columns<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ColumnInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn indexes<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<IndexInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn indexes<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<IndexInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn foreign_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ForeignKeyInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn foreign_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
table: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<ForeignKeyInfo>, OxiSqlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn execute_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait,
fn execute_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait,
Source§fn query_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait,
fn query_named<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: &'life2 [(&'life3 str, &'life4 dyn ToSqlValue)],
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait,
Source§fn last_warnings(&self) -> Vec<SqlWarning>
fn last_warnings(&self) -> Vec<SqlWarning>
Source§fn query_stream<'a>(
&'a self,
sql: &'a str,
params: &'a [&'a dyn ToSqlValue],
) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>>
fn query_stream<'a>( &'a self, sql: &'a str, params: &'a [&'a dyn ToSqlValue], ) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>>
SELECT and return rows as an async stream. Read more