pub struct Database {
pub inner: Connection,
}Expand description
Database connection wrapper for Turso in Cloudflare Workers
Provides a high-level interface for connecting to and interacting with Turso databases in WebAssembly environments, specifically optimized for Cloudflare Workers.
§Examples
use libsql_orm::Database;
async fn connect_example() -> Result<(), Box<dyn std::error::Error>> {
let db = Database::new_connect(
"libsql://your-db.turso.io",
"your-auth-token"
).await?;
Ok(())
}Fields§
§inner: ConnectionImplementations§
Source§impl Database
impl Database
pub async fn new_connect(_url: &str, _token: &str) -> Result<Self, LibsqlError>
Sourcepub async fn query(
&self,
sql: &str,
params: Vec<LibsqlValue>,
) -> Result<LibsqlRows, LibsqlError>
pub async fn query( &self, sql: &str, params: Vec<LibsqlValue>, ) -> Result<LibsqlRows, LibsqlError>
Executes a SQL query with parameters
§Arguments
sql- The SQL query stringparams- Vector of parameters to bind to the query
§Returns
Returns a Result containing Rows iterator or a libsql::Error
§Examples
use libsql_orm::Database;
async fn query_example(db: &Database) -> Result<(), Box<dyn std::error::Error>> {
let rows = db.query(
"SELECT * FROM users WHERE age > ?",
vec![libsql::Value::Integer(18)]
).await?;
Ok(())
}Sourcepub async fn execute(
&self,
sql: &str,
params: Vec<LibsqlValue>,
) -> Result<u64, LibsqlError>
pub async fn execute( &self, sql: &str, params: Vec<LibsqlValue>, ) -> Result<u64, LibsqlError>
Execute a SQL statement with parameters
Trait Implementations§
Source§impl From<Connection> for Database
Available on non-WebAssembly and crate feature libsql only.
impl From<Connection> for Database
Available on non-WebAssembly and crate feature
libsql only.Source§fn from(inner: Connection) -> Self
fn from(inner: Connection) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more