pub struct Database { /* private fields */ }Expand description
A collection of tables and indexes over them.
A database also owns the memory pools used by its tables.
Implementations§
Source§impl Database
impl Database
pub fn run_rule_set( &mut self, rule_set: &RuleSet, report_level: ReportLevel, ) -> RuleSetReport
Source§impl Database
impl Database
Sourcepub fn new() -> Database
pub fn new() -> Database
Create an empty Database.
Queries are executed using the current rayon thread pool, which defaults to the global thread pool.
Sourcepub fn new_rule_set(&mut self) -> RuleSetBuilder<'_>
pub fn new_rule_set(&mut self) -> RuleSetBuilder<'_>
Initialize a new rulse set to run against this database.
Sourcepub fn add_external_function(
&mut self,
f: Box<dyn ExternalFunction + 'static>,
) -> ExternalFunctionId
pub fn add_external_function( &mut self, f: Box<dyn ExternalFunction + 'static>, ) -> ExternalFunctionId
Add a new external function to the database.
Sourcepub fn free_external_function(&mut self, id: ExternalFunctionId)
pub fn free_external_function(&mut self, id: ExternalFunctionId)
Free an existing external function. Make sure not to use id afterwards.
pub fn base_values(&self) -> &BaseValues
pub fn base_values_mut(&mut self) -> &mut BaseValues
pub fn container_values(&self) -> &ContainerValues
pub fn container_values_mut(&mut self) -> &mut ContainerValues
pub fn rebuild_containers(&mut self, table_id: TableId) -> bool
Sourcepub fn apply_rebuild(
&mut self,
func_id: TableId,
to_rebuild: &[TableId],
next_ts: Value,
) -> bool
pub fn apply_rebuild( &mut self, func_id: TableId, to_rebuild: &[TableId], next_ts: Value, ) -> bool
Apply the value-level rebuild encoded by func_id to all the tables in to_rebuild.
The native Table::apply_rebuild method takes a next_ts argument for filling in new
values in a table like crate::SortedWritesTable where values in a certain column need
to be inserted in sorted order; the next_ts argument to this method is passed to
apply_rebuild for this purpose.
Sourcepub fn with_execution_state<R>(
&self,
f: impl FnOnce(&mut ExecutionState<'_>) -> R,
) -> R
pub fn with_execution_state<R>( &self, f: impl FnOnce(&mut ExecutionState<'_>) -> R, ) -> R
Run f with access to an ExecutionState mapped to this database.
Sourcepub fn estimate_size(&self, table: TableId, c: Option<Constraint>) -> usize
pub fn estimate_size(&self, table: TableId, c: Option<Constraint>) -> usize
Estimate the size of the table. If a constraint is provided, return an estimate of the size of the subset of the table matching the constraint.
Sourcepub fn add_counter(&mut self) -> CounterId
pub fn add_counter(&mut self) -> CounterId
Create a new counter for this database.
These counters can be used to generate unique ids as part of an action.
Sourcepub fn inc_counter(&self, counter: CounterId) -> usize
pub fn inc_counter(&self, counter: CounterId) -> usize
Increment the given counter and return its previous value.
Sourcepub fn read_counter(&self, counter: CounterId) -> usize
pub fn read_counter(&self, counter: CounterId) -> usize
Get the current value of the given counter.
Sourcepub fn merge_all(&mut self) -> bool
pub fn merge_all(&mut self) -> bool
A helper for merging all pending updates. Used to write to the database after updates have been staged. Returns true if any tuples were added.
Exposed for testing purposes.
Useful for out-of-band insertions into the database.
Sourcepub fn merge_table(&mut self, table: TableId) -> bool
pub fn merge_table(&mut self, table: TableId) -> bool
A low-level helper for merging pending updates to a particular function.
Callers should prefer merge_all, as the process of merging the data
for a particular table may cause other updates to be buffered
elesewhere. The merge_all method runs merges to a fixed point to avoid
surprises here.
Sourcepub fn next_table_id(&self) -> TableId
pub fn next_table_id(&self) -> TableId
Get id of the next table to be added to the database.
This can be useful for “knot tying”, when tables need to reference their own id.
Sourcepub fn add_table<T: Table + Sized + 'static>(
&mut self,
table: T,
read_deps: impl IntoIterator<Item = TableId>,
write_deps: impl IntoIterator<Item = TableId>,
) -> TableId
pub fn add_table<T: Table + Sized + 'static>( &mut self, table: T, read_deps: impl IntoIterator<Item = TableId>, write_deps: impl IntoIterator<Item = TableId>, ) -> TableId
Add a table with the given schema to the database.
The table must have a compatible spec with types (e.g. same number of
columns).
pub fn add_table_named<T: Table + Sized + 'static>( &mut self, table: T, name: Arc<str>, read_deps: impl IntoIterator<Item = TableId>, write_deps: impl IntoIterator<Item = TableId>, ) -> TableId
Sourcepub fn get_table(&self, table: TableId) -> &WrappedTable
pub fn get_table(&self, table: TableId) -> &WrappedTable
Get direct mutable access to the table.
This method is useful for out-of-band access to databse state.
NOTE: It is legal to call Table::new_buffer on the returned table handle, and use
that to stage updates to the given table via MutationBuffer::stage_insert or
MutationBuffer::stage_remove, however this is likely to be a source of bugs.
Updates staged in this way will not cause table to be marked as having pending changes in
the next call to Database::merge_all. Instead, such users should use
Database::new_buffer, which plumbs this signal through correctly, or better yet,
perform all updates through an ExecutionState or a crate::RuleBuilder. If these
options do not work, then calling Database::merge_table directly will force a merge
call on the table.
Sourcepub fn get_table_info(&self, table: TableId) -> &TableInfo
pub fn get_table_info(&self, table: TableId) -> &TableInfo
Get a handle on the given table along with metadata about it.
NOTE: See the note on Database::get_table around manually staging updates.
Sourcepub fn new_buffer(&self, id: TableId) -> Box<dyn MutationBuffer>
pub fn new_buffer(&self, id: TableId) -> Box<dyn MutationBuffer>
Create a new mutation buffer for the table with id id.
This will marked the given table as potentially changed for the next round of merging.
Unlike calling Table::new_buffer on a table returned from a getter, this method also
triggers change notification metadata that is read by Database::merge_all.
Sourcepub fn get_table_mut(&mut self, id: TableId) -> &mut dyn Table
pub fn get_table_mut(&mut self, id: TableId) -> &mut dyn Table
Get direct mutable access to the table.
This method is useful for out-of-band access to databse state.
NOTE: See the warning around staging updates to handles returned through this method in
the documentation for Database::get_table.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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