pub struct Database { /* private fields */ }Expand description
The main entry point for Bottle ORM database operations.
Database manages a connection pool and provides methods for starting
transactions, creating tables, and building queries for models.
It is designed to be thread-safe and easily shared across an application
(internally uses an Arc for the connection pool).
Implementations§
Source§impl Database
impl Database
Sourcepub fn builder() -> DatabaseBuilder
pub fn builder() -> DatabaseBuilder
Creates a new DatabaseBuilder for configuring the connection.
Sourcepub async fn connect(url: &str) -> Result<Self, Error>
pub async fn connect(url: &str) -> Result<Self, Error>
Connects to a database using the provided connection string.
This is a convenience method that uses default builder settings.
§Arguments
url- A database connection URL (e.g., “postgres://user:pass@localhost/db”)
Sourcepub fn migrator(&self) -> Migrator<'_>
pub fn migrator(&self) -> Migrator<'_>
Returns a new Migrator instance for managing schema changes.
Sourcepub async fn begin(&self) -> Result<Transaction<'_>, Error>
pub async fn begin(&self) -> Result<Transaction<'_>, Error>
Starts a new database transaction.
Sourcepub async fn table_exists(&self, table_name: &str) -> Result<bool, Error>
pub async fn table_exists(&self, table_name: &str) -> Result<bool, Error>
Checks if a table exists in the database.
Sourcepub async fn create_table<T: Model>(&self) -> Result<(), Error>
pub async fn create_table<T: Model>(&self) -> Result<(), Error>
Creates a table based on the provided Model metadata.
Sourcepub async fn sync_table<T: Model>(&self) -> Result<(), Error>
pub async fn sync_table<T: Model>(&self) -> Result<(), Error>
Synchronizes a table schema by adding missing columns or indexes.
Sourcepub async fn get_table_columns(
&self,
table_name: &str,
) -> Result<Vec<String>, Error>
pub async fn get_table_columns( &self, table_name: &str, ) -> Result<Vec<String>, Error>
Returns the current columns of a table.
Trait Implementations§
Source§impl Connection for Database
impl Connection for Database
fn execute<'a, 'q: 'a>( &'a self, sql: &'q str, args: AnyArguments<'q>, ) -> BoxFuture<'a, Result<AnyQueryResult, Error>>
fn fetch_all<'a, 'q: 'a>( &'a self, sql: &'q str, args: AnyArguments<'q>, ) -> BoxFuture<'a, Result<Vec<AnyRow>, Error>>
fn fetch_one<'a, 'q: 'a>( &'a self, sql: &'q str, args: AnyArguments<'q>, ) -> BoxFuture<'a, Result<AnyRow, Error>>
fn fetch_optional<'a, 'q: 'a>( &'a self, sql: &'q str, args: AnyArguments<'q>, ) -> BoxFuture<'a, Result<Option<AnyRow>, Error>>
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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