pub struct DatabaseConn {
pub conn: Connection,
}Expand description
Core database connection wrapper
DatabaseConn provides a thin wrapper around SQLite connections,
handling both file-based and in-memory databases with consistent
configuration and error handling.
Fields§
§conn: ConnectionImplementations§
Source§impl DatabaseConn
impl DatabaseConn
Sourcepub fn open(path: Option<&str>) -> Result<Self>
pub fn open(path: Option<&str>) -> Result<Self>
Open a database at the specified path
If the path is None, an in-memory database is created.
The database is configured with optimal settings for monocle’s use case.
Sourcepub fn new(path: &Option<String>) -> Result<Self>
pub fn new(path: &Option<String>) -> Result<Self>
Create a new database connection (backward-compatible signature)
This method accepts &Option<String> for compatibility with existing code.
Prefer using open() with Option<&str> for new code.
Sourcepub fn open_path(path: &str) -> Result<Self>
pub fn open_path(path: &str) -> Result<Self>
Open a database at the specified path (convenience method)
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Create an in-memory database
Sourcepub fn execute_with_params<P: Params>(
&self,
sql: &str,
params: P,
) -> Result<usize>
pub fn execute_with_params<P: Params>( &self, sql: &str, params: P, ) -> Result<usize>
Execute a SQL statement with parameters
Sourcepub fn transaction(&self) -> Result<Transaction<'_>>
pub fn transaction(&self) -> Result<Transaction<'_>>
Begin an unchecked transaction
This is useful for batch operations where we want to commit multiple statements atomically.
Sourcepub fn table_exists(&self, table_name: &str) -> Result<bool>
pub fn table_exists(&self, table_name: &str) -> Result<bool>
Check if a table exists in the database
Sourcepub fn table_count(&self, table_name: &str) -> Result<u64>
pub fn table_count(&self, table_name: &str) -> Result<u64>
Get the row count for a table
Auto Trait Implementations§
impl !Freeze for DatabaseConn
impl !RefUnwindSafe for DatabaseConn
impl Send for DatabaseConn
impl !Sync for DatabaseConn
impl Unpin for DatabaseConn
impl !UnwindSafe for DatabaseConn
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§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