pub struct Database { /* private fields */ }Expand description
A Turso database with a pool of connections.
Cloning is cheap; every clone shares the same engine handle and pool.
Implementations§
Source§impl Database
impl Database
Sourcepub async fn connect(
options: impl Into<ConnectOptions>,
) -> Result<Database, Error>
pub async fn connect( options: impl Into<ConnectOptions>, ) -> Result<Database, Error>
Opens the database described by options.
One connection is opened eagerly and dropped back into the pool so that a bad path, a wrong key or a rejected pragma fails here rather than on the first query.
§Errors
Returns Error::InvalidOptions when encryption is combined with a
sync source, and Error::Turso with ErrorKind::Connection or
ErrorKind::Other when the engine cannot open the database, open
the first connection or apply its pragmas.
Sourcepub fn options(&self) -> &ConnectOptions
pub fn options(&self) -> &ConnectOptions
The options this database was opened with.
Sourcepub async fn ping(&self) -> Result<(), Error>
pub async fn ping(&self) -> Result<(), Error>
Checks that the database answers queries.
§Errors
Returns Error::PoolTimeout when no connection is free within the
acquire timeout, Error::Misuse when the pool is closed, and
Error::Turso when a connection cannot be opened or the probe
query fails.
Sourcepub async fn push(&self) -> Result<(), Error>
Available on crate feature sync only.
pub async fn push(&self) -> Result<(), Error>
sync only.Pushes local changes to Turso Cloud — embedded replica only.
§Errors
Returns Error::InvalidOptions when this database is not a
replica, and Error::Turso when the sync fails.
Sourcepub async fn pull(&self) -> Result<bool, Error>
Available on crate feature sync only.
pub async fn pull(&self) -> Result<bool, Error>
sync only.Pulls remote changes from Turso Cloud — embedded replica only — and returns whether anything changed.
§Errors
Returns Error::InvalidOptions when this database is not a
replica, and Error::Turso when the sync fails.
Trait Implementations§
Source§impl ConnectionTrait for Database
impl ConnectionTrait for Database
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
statement: Statement,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Database: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
statement: Statement,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Database: 'async_trait,
Source§fn execute_unprepared<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Database: 'async_trait,
fn execute_unprepared<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Database: 'async_trait,
;-separated statements without parameters.Source§impl ConnectionTrait for &Database
impl ConnectionTrait for &Database
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
statement: Statement,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
&Database: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
statement: Statement,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
&Database: 'async_trait,
Source§fn execute_unprepared<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
&Database: 'async_trait,
fn execute_unprepared<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
&Database: 'async_trait,
;-separated statements without parameters.Source§impl StreamTrait for Database
impl StreamTrait for Database
Source§impl TransactionTrait for Database
impl TransactionTrait for Database
Source§fn begin<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Transaction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Database: 'async_trait,
fn begin<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Transaction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Database: 'async_trait,
BEGIN DEFERRED, or a savepoint when called on a
transaction. Read moreSource§fn begin_with_mode<'life0, 'async_trait>(
&'life0 self,
mode: TransactionMode,
) -> Pin<Box<dyn Future<Output = Result<Transaction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Database: 'async_trait,
fn begin_with_mode<'life0, 'async_trait>(
&'life0 self,
mode: TransactionMode,
) -> Pin<Box<dyn Future<Output = Result<Transaction, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Database: 'async_trait,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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