pub struct Database { /* private fields */ }Expand description
Async database using the backend selected by the crate feature.
Implementations§
Source§impl Database
impl Database
pub async fn connect(url: impl Into<String>) -> Result<Self, OrmError>
pub async fn connect_with_pool_size( url: impl Into<String>, size: usize, ) -> Result<Self, OrmError>
pub async fn connect_in_memory() -> Result<Self, OrmError>
pub async fn execute(&self, ast: QueryAst) -> Result<ExecuteResult, OrmError>
Sourcepub async fn execute_sql(
&self,
sql: impl Into<String>,
params: Vec<DatabaseValue>,
) -> Result<ExecuteResult, OrmError>
pub async fn execute_sql( &self, sql: impl Into<String>, params: Vec<DatabaseValue>, ) -> Result<ExecuteResult, OrmError>
Executes explicitly supplied SQL with bound values. SQL syntax is backend-specific.
pub async fn query_sql( &self, sql: impl Into<String>, params: Vec<DatabaseValue>, ) -> Result<Vec<Row>, OrmError>
pub async fn create_table<M: Model>(&self) -> Result<ExecuteResult, OrmError>
Sourcepub async fn insert<M: Model>(
&self,
model: &M,
) -> Result<ExecuteResult, OrmError>
pub async fn insert<M: Model>( &self, model: &M, ) -> Result<ExecuteResult, OrmError>
Inserts supplied UUID keys, omitting generated integer keys and managed timestamps.
pub async fn fetch_all<M: Model + Send + 'static>( &self, query: SelectQuery<M>, ) -> Result<Vec<M>, OrmError>
pub async fn fetch_one<M: Model + Send + 'static>( &self, query: SelectQuery<M>, ) -> Result<Option<M>, OrmError>
pub async fn get<M: Model + Send + 'static>( &self, id: M::PrimaryKey, ) -> Result<Option<M>, OrmError>
pub async fn all<M: Model + Send + 'static>(&self) -> Result<Vec<M>, OrmError>
pub async fn count<M: Model + Send + 'static>(&self) -> Result<usize, OrmError>
pub async fn count_query<M: Model + Send + 'static>( &self, query: SelectQuery<M>, ) -> Result<usize, OrmError>
pub fn create<M: Model>(&self) -> CreateBuilder<'_, M>
pub fn update<M: Model>(&self, id: M::PrimaryKey) -> UpdateBuilder<'_, M>
pub async fn delete<M: Model + Send + 'static>( &self, id: M::PrimaryKey, ) -> Result<bool, OrmError>
pub fn query<M: Model>(&self) -> DatabaseQuery<M>
pub async fn fetch_by<M, T, V>( &self, field: ModelField<M, T>, value: V, ) -> Result<Vec<M>, OrmError>
pub async fn fetch_by_many<M, T, I, V>( &self, field: ModelField<M, T>, values: I, ) -> Result<Vec<M>, OrmError>
Sourcepub async fn transaction<T, F>(&self, action: F) -> Result<T, OrmError>
pub async fn transaction<T, F>(&self, action: F) -> Result<T, OrmError>
Runs one serializable async ORM transaction. Unfinished transactions are
rolled back before a cancelled transaction’s connection is recycled.
Use |tx| Box::pin(async move { ... }) and await transaction methods.
Sourcepub async fn transaction_with_isolation<T, F>(
&self,
isolation: IsolationLevel,
action: F,
) -> Result<T, OrmError>
pub async fn transaction_with_isolation<T, F>( &self, isolation: IsolationLevel, action: F, ) -> Result<T, OrmError>
SQLite uses its serializable snapshot for every requested isolation level.
Sourcepub async fn typed_transaction<T, F>(&self, action: F) -> Result<T, OrmError>
👎Deprecated since 0.3.0: use Database::transaction instead
pub async fn typed_transaction<T, F>(&self, action: F) -> Result<T, OrmError>
use Database::transaction instead
Compatibility alias for Self::transaction.
Sourcepub async fn raw_transaction<T, F>(&self, action: F) -> Result<T, OrmError>
pub async fn raw_transaction<T, F>(&self, action: F) -> Result<T, OrmError>
SQLite-only escape hatch for direct driver operations.
pub async fn migrate(&self, graph: MigrationGraph) -> Result<usize, OrmError>
pub async fn migrate_to( &self, graph: MigrationGraph, target: Option<MigrationId>, ) -> Result<usize, OrmError>
pub async fn migration_history( &self, ) -> Result<HashMap<(String, String), String>, OrmError>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Database
impl !UnwindSafe for Database
impl Freeze for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin 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