pub struct Db<S> { /* private fields */ }Expand description
The database object of Cozo.
Implementations§
Source§impl<'s, S: Storage<'s>> Db<S>
impl<'s, S: Storage<'s>> Db<S>
Sourcepub fn new(storage: S) -> Result<Self>
pub fn new(storage: S) -> Result<Self>
Create a new database object with the given storage.
You must call initialize immediately after creation.
Due to lifetime restrictions we are not able to call that for you automatically.
Sourcepub fn initialize(&'s self) -> Result<()>
pub fn initialize(&'s self) -> Result<()>
Must be called after creation of the database to initialize the runtime state.
Sourcepub fn run_multi_transaction(
&'s self,
is_write: bool,
payloads: Receiver<TransactionPayload>,
results: Sender<Result<NamedRows>>,
)
pub fn run_multi_transaction( &'s self, is_write: bool, payloads: Receiver<TransactionPayload>, results: Sender<Result<NamedRows>>, )
Run a multi-transaction. A command should be sent to payloads, and the result should be
retrieved from results. A transaction ends when it receives a Commit or Abort,
or when a query is not successful. After a transaction ends, sending / receiving from
the channels will fail.
Write transactions may block other reads, but we guarantee that this does not happen for the RocksDB backend.
Sourcepub fn get_fixed_rules(&'s self) -> BTreeMap<String, Arc<Box<dyn FixedRule>>>
pub fn get_fixed_rules(&'s self) -> BTreeMap<String, Arc<Box<dyn FixedRule>>>
This returns the set of fixed rule implementations for this specific backend.
Sourcepub fn run_script(
&'s self,
payload: &str,
params: BTreeMap<String, DataValue>,
mutability: ScriptMutability,
) -> Result<NamedRows>
pub fn run_script( &'s self, payload: &str, params: BTreeMap<String, DataValue>, mutability: ScriptMutability, ) -> Result<NamedRows>
Run the CozoScript passed in. The params argument is a map of parameters.
Sourcepub fn run_script_read_only(
&'s self,
payload: &str,
params: BTreeMap<String, DataValue>,
) -> Result<NamedRows>
pub fn run_script_read_only( &'s self, payload: &str, params: BTreeMap<String, DataValue>, ) -> Result<NamedRows>
Run the CozoScript passed in. The params argument is a map of parameters.
Sourcepub fn run_script_ast(
&'s self,
payload: CozoScript,
cur_vld: ValidityTs,
mutability: ScriptMutability,
) -> Result<NamedRows>
pub fn run_script_ast( &'s self, payload: CozoScript, cur_vld: ValidityTs, mutability: ScriptMutability, ) -> Result<NamedRows>
Run the AST CozoScript passed in.
Sourcepub fn export_relations<I, T>(
&'s self,
relations: I,
) -> Result<BTreeMap<String, NamedRows>>
pub fn export_relations<I, T>( &'s self, relations: I, ) -> Result<BTreeMap<String, NamedRows>>
Export relations to JSON data.
relations contains names of the stored relations to export.
Sourcepub fn import_relations(
&'s self,
data: BTreeMap<String, NamedRows>,
) -> Result<()>
pub fn import_relations( &'s self, data: BTreeMap<String, NamedRows>, ) -> Result<()>
Import relations. The argument data accepts data in the shape of
what was returned by Self::export_relations.
The target stored relations must already exist in the database.
Any associated indices will be updated.
Note that triggers and callbacks are not run for the relations, if any exists. If you need to activate triggers or callbacks, use queries with parameters.
Sourcepub fn backup_db(&'s self, out_file: impl AsRef<Path>) -> Result<()>
pub fn backup_db(&'s self, out_file: impl AsRef<Path>) -> Result<()>
Backup the running database into an Sqlite file
Sourcepub fn restore_backup(&'s self, in_file: impl AsRef<Path>) -> Result<()>
pub fn restore_backup(&'s self, in_file: impl AsRef<Path>) -> Result<()>
Restore from an Sqlite backup
Sourcepub fn import_from_backup(
&'s self,
in_file: impl AsRef<Path>,
relations: &[String],
) -> Result<()>
pub fn import_from_backup( &'s self, in_file: impl AsRef<Path>, relations: &[String], ) -> Result<()>
Import data from relations in a backup file. The target stored relations must already exist in the database, and it must not have any associated indices. If you want to import into relations with indices, use Db::import_relations.
Note that triggers and callbacks are not run for the relations, if any exists. If you need to activate triggers or callbacks, use queries with parameters.
Sourcepub fn register_fixed_rule<R>(&self, name: String, rule_impl: R) -> Result<()>where
R: FixedRule + 'static,
pub fn register_fixed_rule<R>(&self, name: String, rule_impl: R) -> Result<()>where
R: FixedRule + 'static,
Register a custom fixed rule implementation.
Sourcepub fn unregister_fixed_rule(&self, name: &str) -> Result<bool>
pub fn unregister_fixed_rule(&self, name: &str) -> Result<bool>
Unregister a custom fixed rule implementation.
Sourcepub fn register_callback(
&self,
relation: &str,
capacity: Option<usize>,
) -> (u32, Receiver<(CallbackOp, NamedRows, NamedRows)>)
pub fn register_callback( &self, relation: &str, capacity: Option<usize>, ) -> (u32, Receiver<(CallbackOp, NamedRows, NamedRows)>)
Register callback channel to receive changes when the requested relation are successfully committed. The returned ID can be used to unregister the callback channel.
Sourcepub fn unregister_callback(&self, id: u32) -> bool
pub fn unregister_callback(&self, id: u32) -> bool
Unregister callbacks/channels to run when changes to relations are committed.
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for Db<S>where
S: Freeze,
impl<S> RefUnwindSafe for Db<S>where
S: RefUnwindSafe,
impl<S> Send for Db<S>where
S: Send,
impl<S> Sync for Db<S>where
S: Sync,
impl<S> Unpin for Db<S>where
S: Unpin,
impl<S> UnwindSafe for Db<S>where
S: 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> 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 moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>
Source§fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>
Source§fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>
Source§fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>
Source§fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>
Source§fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>
Source§fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>
Source§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
Source§fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>
Source§fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>
Source§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
Source§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
Source§fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
Source§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
Source§fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>
Source§fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>
Source§fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>
Source§fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>
Source§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
Source§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
Source§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
Source§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
Source§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
Source§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
Source§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
Source§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
Source§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
Source§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
Source§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
Source§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
Source§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
Source§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
Source§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
Source§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
Source§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
Source§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
Source§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
Source§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
Source§fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>
Source§fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>
Source§fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>
Source§fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>
Source§fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
fn blink<'a>(&'a self) -> BlinkDisplay<'a, Self>
Source§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
Source§fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>
Source§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more