pub struct Database<A: ConcurrentAllocator = DynAllocator> {
pub db_file: Arc<dyn DatabaseStorage>,
pub path: String,
pub io: Arc<dyn IO>,
/* private fields */
}Expand description
The Database object contains per database file state that is shared
between multiple connections.
Do that Database object is cached and can be long lived. DO NOT store anything sensitive like
encryption key here.
Fields§
§db_file: Arc<dyn DatabaseStorage>§path: String§io: Arc<dyn IO>Implementations§
Source§impl Database
impl Database
pub fn open_with_vfs( &self, path: &str, vfs: &str, ) -> Result<(Arc<dyn IO>, Arc<Database>)>
Sourcepub fn register_global_builtin_extensions(&self) -> Result<(), String>
pub fn register_global_builtin_extensions(&self) -> Result<(), String>
Register any built-in extensions that can be stored on the Database so we do not have to register these once-per-connection, and the connection can just extend its symbol table
Source§impl Database
impl Database
Sourcepub fn is_in_memory_db(&self) -> bool
pub fn is_in_memory_db(&self) -> bool
Returns true if this database is backed by MemoryIO.
pub fn open_file(io: Arc<dyn IO>, path: &str) -> Result<Arc<Database>>
Open or retrieve a shared named in-memory database.
Multiple connections to the same name share a single Database,
matching SQLite’s file:name?mode=memory&cache=shared semantics.
pub fn open_file_with_flags( io: Arc<dyn IO>, path: &str, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, ) -> Result<Arc<Database>>
pub fn open_file_with_flags_and_durable_storage( io: Arc<dyn IO>, path: &str, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, durable_storage: Option<Arc<dyn DurableStorage>>, ) -> Result<Arc<Database>>
pub fn open( io: Arc<dyn IO>, path: &str, db_file: Arc<dyn DatabaseStorage>, ) -> Result<Arc<Database>>
pub fn open_with_flags( io: Arc<dyn IO>, path: &str, db_file: Arc<dyn DatabaseStorage>, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, durable_storage: Option<Arc<dyn DurableStorage>>, ) -> Result<Arc<Database>>
pub fn open_with_flags_with_allocator( io: Arc<dyn IO>, path: &str, db_file: Arc<dyn DatabaseStorage>, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, durable_storage: Option<Arc<dyn DurableStorage>>, allocator: DynAllocator, ) -> Result<Arc<Database>>
Sourcepub fn open_with_flags_async(
state: &mut OpenDbAsyncState,
io: Arc<dyn IO>,
path: &str,
db_file: Arc<dyn DatabaseStorage>,
flags: OpenFlags,
opts: DatabaseOpts,
encryption_opts: Option<EncryptionOpts>,
durable_storage: Option<Arc<dyn DurableStorage>>,
) -> Result<IOResult<Arc<Database>>>
pub fn open_with_flags_async( state: &mut OpenDbAsyncState, io: Arc<dyn IO>, path: &str, db_file: Arc<dyn DatabaseStorage>, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, durable_storage: Option<Arc<dyn DurableStorage>>, ) -> Result<IOResult<Arc<Database>>>
async flow of opening the database this is important to have open async, otherwise sync-engine will not work properly for cases when schema table span multiple pages (so, potentially network IO is needed to load them)
Uses the database registry to ensure single Database instance per file within a process.
Caller must drive the IO loop and pass state between calls.
An Opening sentinel in the registry prevents concurrent opens of the same path
without holding the mutex across I/O yields.
pub fn open_with_flags_async_with_allocator( state: &mut OpenDbAsyncState, io: Arc<dyn IO>, path: &str, db_file: Arc<dyn DatabaseStorage>, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, durable_storage: Option<Arc<dyn DurableStorage>>, allocator: DynAllocator, ) -> Result<IOResult<Arc<Database>>>
Sourcepub fn open_with_flags_bypass_registry_async(
state: &mut OpenDbAsyncState,
io: Arc<dyn IO>,
path: &str,
wal_path: Option<&str>,
db_file: Arc<dyn DatabaseStorage>,
flags: OpenFlags,
opts: DatabaseOpts,
encryption_opts: Option<EncryptionOpts>,
durable_storage: Option<Arc<dyn DurableStorage>>,
) -> Result<IOResult<Arc<Database>>>
pub fn open_with_flags_bypass_registry_async( state: &mut OpenDbAsyncState, io: Arc<dyn IO>, path: &str, wal_path: Option<&str>, db_file: Arc<dyn DatabaseStorage>, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, durable_storage: Option<Arc<dyn DurableStorage>>, ) -> Result<IOResult<Arc<Database>>>
Async version of database opening that returns IOResult. Caller must drive the IO loop and pass state between calls. This is useful for sync engine which needs to yield on IO.
pub fn get_database_canonical_path(&self) -> String
pub fn connect(self: &Arc<Database>) -> Result<Arc<Connection>>
Sourcepub fn connect_with_encryption(
self: &Arc<Database>,
encryption_key: Option<EncryptionKey>,
) -> Result<Arc<Connection>>
pub fn connect_with_encryption( self: &Arc<Database>, encryption_key: Option<EncryptionKey>, ) -> Result<Arc<Connection>>
Connect with an encryption key. Use this when opening an encrypted database where the key is known at connect time.
pub fn is_readonly(&self) -> bool
pub fn io_for_path(path: &str) -> Result<Arc<dyn IO>>
pub fn io_for_vfs<S: AsRef<str> + Display>(vfs: S) -> Result<Arc<dyn IO>>
Sourcepub fn open_new<S>(
path: &str,
vfs: Option<S>,
flags: OpenFlags,
opts: DatabaseOpts,
encryption_opts: Option<EncryptionOpts>,
) -> Result<(Arc<dyn IO>, Arc<Database>)>
pub fn open_new<S>( path: &str, vfs: Option<S>, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, ) -> Result<(Arc<dyn IO>, Arc<Database>)>
Open a new database file with optionally specifying a VFS without an existing database connection and symbol table to register extensions.
Sourcepub fn register_internal_vtab<T>(&self, table: T) -> Result<String>where
T: InternalVirtualTable + 'static,
pub fn register_internal_vtab<T>(&self, table: T) -> Result<String>where
T: InternalVirtualTable + 'static,
Register an InternalVirtualTable into this database’s catalog. The
table is visible to connections opened after this call and is queryable
like any other table.
Intended for callers that want to surface state as a queryable table
without going through CREATE VIRTUAL TABLE — for example, extensions
contributing metadata tables or alternative-dialect catalogs.
Call before opening connections. Connections that already exist will not pick up the new table unless they re-read the shared schema (e.g. via the usual schema-change path).
pub fn get_mv_store( &self, ) -> impl Deref<Target = Option<Arc<MvStore<MvccClock, DynAllocator>>>>
pub fn experimental_views_enabled(&self) -> bool
pub fn experimental_index_method_enabled(&self) -> bool
pub fn experimental_custom_types_enabled(&self) -> bool
pub fn experimental_encryption_enabled(&self) -> bool
pub fn experimental_autovacuum_enabled(&self) -> bool
pub fn experimental_vacuum_enabled(&self) -> bool
pub fn experimental_mvcc_passive_checkpoint_enabled(&self) -> bool
pub fn experimental_attach_enabled(&self) -> bool
pub fn experimental_generated_columns_enabled(&self) -> bool
pub fn experimental_multiprocess_wal_enabled(&self) -> bool
pub fn experimental_without_rowid_enabled(&self) -> bool
Sourcepub fn mvcc_enabled(&self) -> bool
pub fn mvcc_enabled(&self) -> bool
check if database is currently in MVCC mode
Trait Implementations§
Auto Trait Implementations§
impl<A = DynAllocator> !Freeze for Database<A>
impl<A = DynAllocator> !RefUnwindSafe for Database<A>
impl<A = DynAllocator> !UnwindSafe for Database<A>
impl<A> Send for Database<A>
impl<A> Sync for Database<A>
impl<A> Unpin for Database<A>where
A: Unpin,
impl<A> UnsafeUnpin for Database<A>where
A: UnsafeUnpin,
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<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
Source§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
Source§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.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