Struct libsql::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_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_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 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 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 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<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 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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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