pub struct Database {
pub inner: Connection<CloudflareSender>,
}
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: Connection<CloudflareSender>
Implementations§
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 fn get_connection(&self) -> &Connection<CloudflareSender>
pub fn get_connection(&self) -> &Connection<CloudflareSender>
Gets a reference to the underlying libsql connection
This method provides direct access to the libsql connection for advanced use cases where you need to interact with the libsql API directly.
§Returns
A reference to the underlying Connection<CloudflareSender>
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(())
}
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