Struct Builder

Source
pub struct Builder<T = ()> { /* private fields */ }
Expand description

A builder for Database. This struct can be used to build all variants of Database. These variants include:

  • new_local/Local which means a Database that is just a local libsql database it does no networking and does not connect to any remote database.
  • new_remote_replica/RemoteReplica creates an embedded replica database that will be able to sync from the remote url and delegate writes to the remote primary.
  • new_synced_database/SyncedDatabase creates a database that can be written offline and synced to a remote server.
  • new_local_replica/LocalReplica creates an embedded replica similar to the remote version except you must use Database::sync_frames to sync with the remote. This version also includes the ability to delegate writes to a remote primary.
  • new_remote/Remote creates a database that does not create anything locally but will instead run all queries on the remote database. This is essentially the pure HTTP api.

§Note

Embedded replica’s require a clean database (no database file) or a previously synced database or else it will throw an error to prevent any misuse. To work around this error a user can delete the database and let it resync and create the wal_index metadata file.

Implementations§

Source§

impl Builder<()>

Source

pub fn new_local(path: impl AsRef<Path>) -> Builder<Local>

Available on crate feature core only.

Create a new local database.

Source

pub fn new_remote_replica( path: impl AsRef<Path>, url: String, auth_token: String, ) -> Builder<RemoteReplica>

Available on crate feature replication only.

Create a new remote embedded replica.

Source

pub fn new_local_replica(path: impl AsRef<Path>) -> Builder<LocalReplica>

Available on crate feature replication only.

Create a new local replica.

Source

pub fn new_synced_database( path: impl AsRef<Path>, url: String, auth_token: String, ) -> Builder<SyncedDatabase>

Available on crate feature sync only.

Create a database that can be written offline and synced to a remote server.

Source

pub fn new_remote(url: String, auth_token: String) -> Builder<Remote>

Available on crate feature remote only.

Create a new remote database.

Source§

impl Builder<Local>

Source

pub fn flags(self, flags: OpenFlags) -> Builder<Local>

Available on crate feature core only.

Set [OpenFlags] for this database.

Source

pub fn encryption_config( self, encryption_config: EncryptionConfig, ) -> Builder<Local>

Available on crate feature core only.

Set an encryption config that will encrypt the local database.

Source

pub unsafe fn skip_safety_assert(self, skip: bool) -> Builder<Local>

Available on crate feature core only.

Skip the saftey assert used to ensure that sqlite3 is configured correctly for the way that libsql uses the ffi code. By default, libsql will try to use the SERIALIZED threadsafe mode for sqlite3. This allows us to implement Send/Sync for all the types to allow them to move between threads safely. Due to the fact that sqlite3 has a global config this may conflict with other sqlite3 connections in the same process.

Using this setting is very UNSAFE and you are expected to use the libsql in adherence with the sqlite3 threadsafe rules or else you WILL create undefined behavior. Use at your own risk.

Source

pub async fn build(self) -> Result<Database>

Available on crate feature core only.

Build the local database.

Source§

impl Builder<RemoteReplica>

Source

pub fn connector<C>(self, connector: C) -> Builder<RemoteReplica>
where C: Service<Uri> + Send + Clone + Sync + 'static, C::Response: Socket, C::Future: Send + 'static, C::Error: Into<Box<dyn Error + Send + Sync>>,

Available on crate feature replication only.

Provide a custom http connector that will be used to create http connections.

Source

pub fn encryption_config( self, encryption_config: EncryptionConfig, ) -> Builder<RemoteReplica>

Available on crate feature replication only.

Set an encryption key that will encrypt the local database.

Source

pub fn read_your_writes(self, read_your_writes: bool) -> Builder<RemoteReplica>

Available on crate feature replication only.

Set weather you want writes to be visible locally before the write query returns. This means that you will be able to read your own writes if this is set to true.

§Default

This defaults to true.

Source

pub fn sync_interval(self, duration: Duration) -> Builder<RemoteReplica>

Available on crate feature replication only.

Set the duration at which the replicator will automatically call sync in the background. The sync will continue for the duration that the resulted Database type is alive for, once it is dropped the background task will get dropped and stop.

Source

pub fn sync_protocol(self, protocol: SyncProtocol) -> Builder<RemoteReplica>

Available on crate feature replication only.

Set the duration at which the replicator will automatically call sync in the background. The sync will continue for the duration that the resulted Database type is alive for, once it is dropped the background task will get dropped and stop.

Source

pub fn http_request_callback<F>(self, f: F) -> Builder<RemoteReplica>
where F: Fn(&mut Request<()>) + Send + Sync + 'static,

Available on crate feature replication only.
Source

pub fn namespace(self, namespace: impl Into<String>) -> Builder<RemoteReplica>

Available on crate feature replication only.

Set the namespace that will be communicated to remote replica in the http header.

Source

pub unsafe fn skip_safety_assert(self, skip: bool) -> Builder<RemoteReplica>

Available on crate feature replication only.

Skip the saftey assert used to ensure that sqlite3 is configured correctly for the way that libsql uses the ffi code. By default, libsql will try to use the SERIALIZED threadsafe mode for sqlite3. This allows us to implement Send/Sync for all the types to allow them to move between threads safely. Due to the fact that sqlite3 has a global config this may conflict with other sqlite3 connections in the same process.

Using this setting is very UNSAFE and you are expected to use the libsql in adherence with the sqlite3 threadsafe rules or else you WILL create undefined behavior. Use at your own risk.

Source

pub async fn build(self) -> Result<Database>

Available on crate feature replication only.

Build the remote embedded replica database.

Source§

impl Builder<LocalReplica>

Source

pub fn flags(self, flags: OpenFlags) -> Builder<LocalReplica>

Available on crate feature replication only.

Set [OpenFlags] for this database.

Source

pub fn http_request_callback<F>(self, f: F) -> Builder<LocalReplica>
where F: Fn(&mut Request<()>) + Send + Sync + 'static,

Available on crate feature replication only.
Source

pub async fn build(self) -> Result<Database>

Available on crate feature replication only.

Build the local embedded replica database.

Source§

impl Builder<SyncedDatabase>

Source

pub fn read_your_writes(self, v: bool) -> Builder<SyncedDatabase>

Available on crate feature sync only.
Source

pub fn remote_writes(self, v: bool) -> Builder<SyncedDatabase>

Available on crate feature sync only.
Source

pub fn set_push_batch_size(self, v: u32) -> Builder<SyncedDatabase>

Available on crate feature sync only.
Source

pub fn sync_interval(self, duration: Duration) -> Builder<SyncedDatabase>

Available on crate feature sync only.

Set the duration at which the replicator will automatically call sync in the background. The sync will continue for the duration that the resulted Database type is alive for, once it is dropped the background task will get dropped and stop.

Source

pub fn connector<C>(self, connector: C) -> Builder<SyncedDatabase>
where C: Service<Uri> + Send + Clone + Sync + 'static, C::Response: Socket, C::Future: Send + 'static, C::Error: Into<Box<dyn Error + Send + Sync>>,

Available on crate feature sync only.

Provide a custom http connector that will be used to create http connections.

Source

pub async fn build(self) -> Result<Database>

Available on crate feature sync only.

Build a connection to a local database that can be synced to remote server.

Source§

impl Builder<Remote>

Source

pub fn connector<C>(self, connector: C) -> Builder<Remote>
where C: Service<Uri> + Send + Clone + Sync + 'static, C::Response: Socket, C::Future: Send + 'static, C::Error: Into<Box<dyn Error + Send + Sync>>,

Available on crate feature remote only.

Provide a custom http connector that will be used to create http connections.

Source

pub fn namespace(self, namespace: impl Into<String>) -> Builder<Remote>

Available on crate feature remote only.

Set the namespace that will be communicated to the remote in the http header.

Source

pub async fn build(self) -> Result<Database>

Available on crate feature remote only.

Build the remote database client.

Auto Trait Implementations§

§

impl<T> Freeze for Builder<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Builder<T>
where T: RefUnwindSafe,

§

impl<T> Send for Builder<T>
where T: Send,

§

impl<T> Sync for Builder<T>
where T: Sync,

§

impl<T> Unpin for Builder<T>
where T: Unpin,

§

impl<T> UnwindSafe for Builder<T>
where T: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more