pub struct Database {
pub conn: Connection,
}Expand description
Represents a database connection and provides methods for interacting with it.
The Database struct is the primary entry point for interacting with the database.
It holds the connection pool and provides methods for creating new connections,
running migrations, and performing other database-level operations.
Fields§
§conn: ConnectionThe database connection.
Implementations§
Source§impl Database
impl Database
Sourcepub async fn new(database_url: &str) -> Result<Self, Error>
pub async fn new(database_url: &str) -> Result<Self, Error>
Creates a new database connection.
This method is only available when the turso feature is not enabled.
It uses sqlx to connect to the database specified by the database_url.
§Arguments
database_url- The connection string for the database.
§Returns
A Result containing a new Database instance on success, or an Error on failure.
Sourcepub async fn migrate(&self) -> Result<(), Error>
pub async fn migrate(&self) -> Result<(), Error>
Runs database migrations.
This method iterates over all registered models and applies their migrations to the database. For migrations to be discovered, the models must be imported into the binary where this method is called.
§Example
// In your main.rs
use rusql_alchemy::prelude::*;
use rusql_alchemy::Error;
// Import your models so they can be discovered for migration.
#[allow(unused_imports)]
use crate::models::*;
#[tokio::main]
async fn main() -> Result<(), Error> {
let database = Database::new_local("local.db").await?;
database.migrate().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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more