Skip to main content

Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

Async database using the backend selected by the crate feature.

Implementations§

Source§

impl Database

Source

pub async fn connect(url: impl Into<String>) -> Result<Self, OrmError>

Source

pub async fn connect_with_pool_size( url: impl Into<String>, size: usize, ) -> Result<Self, OrmError>

Source

pub async fn connect_in_memory() -> Result<Self, OrmError>

Source

pub async fn execute(&self, ast: QueryAst) -> Result<ExecuteResult, OrmError>

Source

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.

Source

pub async fn query_sql( &self, sql: impl Into<String>, params: Vec<DatabaseValue>, ) -> Result<Vec<Row>, OrmError>

Source

pub async fn create_table<M: Model>(&self) -> Result<ExecuteResult, OrmError>

Source

pub async fn insert<M: Model>( &self, model: &M, ) -> Result<ExecuteResult, OrmError>

Inserts supplied UUID keys, omitting generated integer keys and managed timestamps.

Source

pub async fn fetch_all<M: Model + Send + 'static>( &self, query: SelectQuery<M>, ) -> Result<Vec<M>, OrmError>

Source

pub async fn fetch_one<M: Model + Send + 'static>( &self, query: SelectQuery<M>, ) -> Result<Option<M>, OrmError>

Source

pub async fn get<M: Model + Send + 'static>( &self, id: M::PrimaryKey, ) -> Result<Option<M>, OrmError>

Source

pub async fn all<M: Model + Send + 'static>(&self) -> Result<Vec<M>, OrmError>

Source

pub async fn count<M: Model + Send + 'static>(&self) -> Result<usize, OrmError>

Source

pub async fn count_query<M: Model + Send + 'static>( &self, query: SelectQuery<M>, ) -> Result<usize, OrmError>

Source

pub fn create<M: Model>(&self) -> CreateBuilder<'_, M>

Source

pub fn update<M: Model>(&self, id: M::PrimaryKey) -> UpdateBuilder<'_, M>

Source

pub async fn delete<M: Model + Send + 'static>( &self, id: M::PrimaryKey, ) -> Result<bool, OrmError>

Source

pub fn query<M: Model>(&self) -> DatabaseQuery<M>

Source

pub async fn fetch_by<M, T, V>( &self, field: ModelField<M, T>, value: V, ) -> Result<Vec<M>, OrmError>
where M: Model + Send + 'static, V: QueryValue<T>,

Source

pub async fn fetch_by_many<M, T, I, V>( &self, field: ModelField<M, T>, values: I, ) -> Result<Vec<M>, OrmError>
where M: Model + Send + 'static, I: IntoIterator<Item = V>, V: QueryValue<T>,

Source

pub async fn transaction<T, F>(&self, action: F) -> Result<T, OrmError>
where T: Send + 'static, F: for<'a> FnOnce(&'a Transaction) -> TransactionFuture<'a, T> + Send,

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.

Source

pub async fn transaction_with_isolation<T, F>( &self, isolation: IsolationLevel, action: F, ) -> Result<T, OrmError>
where T: Send + 'static, F: for<'a> FnOnce(&'a Transaction) -> TransactionFuture<'a, T> + Send,

SQLite uses its serializable snapshot for every requested isolation level.

Source

pub async fn typed_transaction<T, F>(&self, action: F) -> Result<T, OrmError>
where T: Send + 'static, F: for<'a> FnOnce(&'a Transaction) -> TransactionFuture<'a, T> + Send,

👎Deprecated since 0.3.0:

use Database::transaction instead

Compatibility alias for Self::transaction.

Source

pub async fn raw_transaction<T, F>(&self, action: F) -> Result<T, OrmError>
where T: Send + 'static, F: FnOnce(&Connection) -> Result<T> + Send + 'static,

SQLite-only escape hatch for direct driver operations.

Source

pub async fn migrate(&self, graph: MigrationGraph) -> Result<usize, OrmError>

Source

pub async fn migrate_to( &self, graph: MigrationGraph, target: Option<MigrationId>, ) -> Result<usize, OrmError>

Source

pub async fn migration_history( &self, ) -> Result<HashMap<(String, String), String>, OrmError>

Trait Implementations§

Source§

impl Clone for Database

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.