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 aDatabase
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 useDatabase::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<()>
impl Builder<()>
Sourcepub fn new_local(path: impl AsRef<Path>) -> Builder<Local>
Available on crate feature core
only.
pub fn new_local(path: impl AsRef<Path>) -> Builder<Local>
core
only.Create a new local database.
Sourcepub fn new_remote_replica(
path: impl AsRef<Path>,
url: String,
auth_token: String,
) -> Builder<RemoteReplica>
Available on crate feature replication
only.
pub fn new_remote_replica( path: impl AsRef<Path>, url: String, auth_token: String, ) -> Builder<RemoteReplica>
replication
only.Create a new remote embedded replica.
Sourcepub fn new_local_replica(path: impl AsRef<Path>) -> Builder<LocalReplica>
Available on crate feature replication
only.
pub fn new_local_replica(path: impl AsRef<Path>) -> Builder<LocalReplica>
replication
only.Create a new local replica.
Sourcepub fn new_synced_database(
path: impl AsRef<Path>,
url: String,
auth_token: String,
) -> Builder<SyncedDatabase>
Available on crate feature sync
only.
pub fn new_synced_database( path: impl AsRef<Path>, url: String, auth_token: String, ) -> Builder<SyncedDatabase>
sync
only.Create a database that can be written offline and synced to a remote server.
Sourcepub fn new_remote(url: String, auth_token: String) -> Builder<Remote>
Available on crate feature remote
only.
pub fn new_remote(url: String, auth_token: String) -> Builder<Remote>
remote
only.Create a new remote database.
Source§impl Builder<Local>
impl Builder<Local>
Sourcepub fn flags(self, flags: OpenFlags) -> Builder<Local>
Available on crate feature core
only.
pub fn flags(self, flags: OpenFlags) -> Builder<Local>
core
only.Set [OpenFlags
] for this database.
Sourcepub fn encryption_config(
self,
encryption_config: EncryptionConfig,
) -> Builder<Local>
Available on crate feature core
only.
pub fn encryption_config( self, encryption_config: EncryptionConfig, ) -> Builder<Local>
core
only.Set an encryption config that will encrypt the local database.
Sourcepub unsafe fn skip_safety_assert(self, skip: bool) -> Builder<Local>
Available on crate feature core
only.
pub unsafe fn skip_safety_assert(self, skip: bool) -> Builder<Local>
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§impl Builder<RemoteReplica>
impl Builder<RemoteReplica>
Sourcepub fn connector<C>(self, connector: C) -> Builder<RemoteReplica>
Available on crate feature replication
only.
pub fn connector<C>(self, connector: C) -> Builder<RemoteReplica>
replication
only.Provide a custom http connector that will be used to create http connections.
Sourcepub fn encryption_config(
self,
encryption_config: EncryptionConfig,
) -> Builder<RemoteReplica>
Available on crate feature replication
only.
pub fn encryption_config( self, encryption_config: EncryptionConfig, ) -> Builder<RemoteReplica>
replication
only.Set an encryption key that will encrypt the local database.
Sourcepub fn read_your_writes(self, read_your_writes: bool) -> Builder<RemoteReplica>
Available on crate feature replication
only.
pub fn read_your_writes(self, read_your_writes: bool) -> Builder<RemoteReplica>
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
.
Sourcepub fn sync_interval(self, duration: Duration) -> Builder<RemoteReplica>
Available on crate feature replication
only.
pub fn sync_interval(self, duration: Duration) -> Builder<RemoteReplica>
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.
Sourcepub fn sync_protocol(self, protocol: SyncProtocol) -> Builder<RemoteReplica>
Available on crate feature replication
only.
pub fn sync_protocol(self, protocol: SyncProtocol) -> Builder<RemoteReplica>
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.
pub fn http_request_callback<F>(self, f: F) -> Builder<RemoteReplica>
replication
only.Sourcepub fn namespace(self, namespace: impl Into<String>) -> Builder<RemoteReplica>
Available on crate feature replication
only.
pub fn namespace(self, namespace: impl Into<String>) -> Builder<RemoteReplica>
replication
only.Set the namespace that will be communicated to remote replica in the http header.
Sourcepub unsafe fn skip_safety_assert(self, skip: bool) -> Builder<RemoteReplica>
Available on crate feature replication
only.
pub unsafe fn skip_safety_assert(self, skip: bool) -> Builder<RemoteReplica>
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§impl Builder<LocalReplica>
impl Builder<LocalReplica>
Source§impl Builder<SyncedDatabase>
impl Builder<SyncedDatabase>
pub fn read_your_writes(self, v: bool) -> Builder<SyncedDatabase>
sync
only.pub fn remote_writes(self, v: bool) -> Builder<SyncedDatabase>
sync
only.pub fn set_push_batch_size(self, v: u32) -> Builder<SyncedDatabase>
sync
only.Sourcepub fn sync_interval(self, duration: Duration) -> Builder<SyncedDatabase>
Available on crate feature sync
only.
pub fn sync_interval(self, duration: Duration) -> Builder<SyncedDatabase>
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§impl Builder<Remote>
impl Builder<Remote>
Sourcepub fn connector<C>(self, connector: C) -> Builder<Remote>
Available on crate feature remote
only.
pub fn connector<C>(self, connector: C) -> Builder<Remote>
remote
only.Provide a custom http connector that will be used to create http connections.
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> 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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request