pub struct Database {
pub inner: Connection,
}Expand description
Database connection wrapper for libsql in Cloudflare Workers
Provides a high-level interface for connecting to and interacting with libsql 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
Sourcepub async fn new_connect(url: &str, token: &str) -> Result<Self, Error>
pub async fn new_connect(url: &str, token: &str) -> Result<Self, Error>
Creates a new database connection to a libsql database
§Arguments
url- The database URL (e.g., “libsql://your-db.turso.io”)token- The authentication token for the database
§Returns
Returns a Result containing the Database instance or a libsql::Error
§Examples
use libsql_orm::Database;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let db = Database::new_connect(
"libsql://your-db.turso.io",
"your-auth-token"
).await?;
println!("Connected to database successfully!");
Ok(())
}Sourcepub async fn query(&self, sql: &str, params: Vec<Value>) -> Result<Rows, Error>
pub async fn query(&self, sql: &str, params: Vec<Value>) -> Result<Rows, Error>
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(())
}Trait Implementations§
Source§impl From<Connection> for Database
Available on non-WebAssembly only.
impl From<Connection> for Database
Available on non-WebAssembly 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request