Skip to main content

Database

Struct Database 

Source
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

Source

pub fn open_with_vfs( &self, path: &str, vfs: &str, ) -> Result<(Arc<dyn IO>, Arc<Database>)>

Source

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

Source

pub fn is_in_memory_db(&self) -> bool

Returns true if this database is backed by MemoryIO.

Source

pub fn open_file(io: Arc<dyn IO>, path: &str) -> Result<Arc<Database>>

Source

pub fn open_shared_memory(name: &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.

Source

pub fn open_file_with_flags( io: Arc<dyn IO>, path: &str, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, ) -> Result<Arc<Database>>

Source

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

Source

pub fn open( io: Arc<dyn IO>, path: &str, db_file: Arc<dyn DatabaseStorage>, ) -> Result<Arc<Database>>

Source

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

Source

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

Source

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.

Source

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

Source

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.

Source

pub fn get_database_canonical_path(&self) -> String

Source

pub fn connect(self: &Arc<Database>) -> Result<Arc<Connection>>

Source

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.

Source

pub fn is_readonly(&self) -> bool

Source

pub fn shared_wal_open_telemetry(&self) -> Result<SharedWalOpenTelemetry>

Source

pub fn io_for_path(path: &str) -> Result<Arc<dyn IO>>

Source

pub fn io_for_vfs<S: AsRef<str> + Display>(vfs: S) -> Result<Arc<dyn IO>>

Source

pub fn open_new<S>( path: &str, vfs: Option<S>, flags: OpenFlags, opts: DatabaseOpts, encryption_opts: Option<EncryptionOpts>, ) -> Result<(Arc<dyn IO>, Arc<Database>)>
where S: AsRef<str> + Display,

Open a new database file with optionally specifying a VFS without an existing database connection and symbol table to register extensions.

Source

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).

Source

pub fn get_mv_store( &self, ) -> impl Deref<Target = Option<Arc<MvStore<MvccClock, DynAllocator>>>>

Source

pub fn experimental_views_enabled(&self) -> bool

Source

pub fn experimental_index_method_enabled(&self) -> bool

Source

pub fn experimental_custom_types_enabled(&self) -> bool

Source

pub fn experimental_encryption_enabled(&self) -> bool

Source

pub fn experimental_autovacuum_enabled(&self) -> bool

Source

pub fn experimental_vacuum_enabled(&self) -> bool

Source

pub fn experimental_mvcc_passive_checkpoint_enabled(&self) -> bool

Source

pub fn experimental_attach_enabled(&self) -> bool

Source

pub fn experimental_generated_columns_enabled(&self) -> bool

Source

pub fn experimental_multiprocess_wal_enabled(&self) -> bool

Source

pub fn experimental_without_rowid_enabled(&self) -> bool

Source

pub fn mvcc_enabled(&self) -> bool

check if database is currently in MVCC mode

Trait Implementations§

Source§

impl Debug for Database

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<K, Q> Comparable<Q> for K
where K: Borrow<Q> + ?Sized, Q: Ord + ?Sized,

Source§

fn compare(&self, key: &Q) -> Ordering

Compare self to key and return their ordering.
Source§

impl<K, Q> Equivalent<Q> for K
where K: Borrow<Q> + ?Sized, Q: Eq + ?Sized,

Source§

fn equivalent(&self, key: &Q) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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