add note about imports not running triggers

main
Ziyang Hu 2 years ago
parent b28b92605c
commit 810bc17e82

@ -282,6 +282,9 @@ impl DbInstance {
} }
} }
/// Import a relation, the data is given as a JSON string, and the returned result is converted into a string /// Import a relation, the data is given as a JSON string, and the returned result is converted into a string
///
/// Note that triggers are _not_ run for the relations, if any exists.
/// If you need to activate triggers, use queries with parameters.
pub fn import_relations_str(&self, data: &str) -> String { pub fn import_relations_str(&self, data: &str) -> String {
match self.import_relations_str_inner(data) { match self.import_relations_str_inner(data) {
Ok(()) => { Ok(()) => {
@ -353,6 +356,9 @@ impl DbInstance {
} }
} }
/// Import relations from an Sqlite backup, with JSON string return value /// Import relations from an Sqlite backup, with JSON string return value
///
/// Note that triggers are _not_ run for the relations, if any exists.
/// If you need to activate triggers, use queries with parameters.
pub fn import_from_backup_str(&self, payload: &str) -> String { pub fn import_from_backup_str(&self, payload: &str) -> String {
match self.import_from_backup_str_inner(payload) { match self.import_from_backup_str_inner(payload) {
Ok(_) => json!({"ok": true}).to_string(), Ok(_) => json!({"ok": true}).to_string(),

@ -195,6 +195,9 @@ impl<'s, S: Storage<'s>> Db<S> {
/// Import relations. The argument `data` accepts data in the shape of /// Import relations. The argument `data` accepts data in the shape of
/// what was returned by [Self::export_relations]. /// what was returned by [Self::export_relations].
/// The target stored relations must already exist in the database. /// The target stored relations must already exist in the database.
///
/// Note that triggers are _not_ run for the relations, if any exists.
/// If you need to activate triggers, use queries with parameters.
pub fn import_relations(&'s self, data: BTreeMap<String, NamedRows>) -> Result<()> { pub fn import_relations(&'s self, data: BTreeMap<String, NamedRows>) -> Result<()> {
#[derive(Debug, Diagnostic, Error)] #[derive(Debug, Diagnostic, Error)]
#[error("cannot import data for relation '{0}': {1}")] #[error("cannot import data for relation '{0}': {1}")]
@ -345,6 +348,9 @@ impl<'s, S: Storage<'s>> Db<S> {
} }
/// Import data from relations in a backup file. /// Import data from relations in a backup file.
/// The target stored relations must already exist in the database. /// The target stored relations must already exist in the database.
///
/// Note that triggers are _not_ run for the relations, if any exists.
/// If you need to activate triggers, use queries with parameters.
pub fn import_from_backup(&'s self, in_file: &str, relations: &[String]) -> Result<()> { pub fn import_from_backup(&'s self, in_file: &str, relations: &[String]) -> Result<()> {
#[cfg(not(feature = "storage-sqlite"))] #[cfg(not(feature = "storage-sqlite"))]
bail!("backup requires the 'storage-sqlite' feature to be enabled"); bail!("backup requires the 'storage-sqlite' feature to be enabled");

@ -147,6 +147,9 @@ pub unsafe extern "C" fn cozo_run_query(
#[no_mangle] #[no_mangle]
/// Import data into relations /// Import data into relations
/// ///
/// Note that triggers are _not_ run for the relations, if any exists.
/// If you need to activate triggers, use queries with parameters.
///
/// `db_id`: the ID representing the database. /// `db_id`: the ID representing the database.
/// `json_payload`: a UTF-8 encoded JSON payload, in the same form as returned by exporting relations. /// `json_payload`: a UTF-8 encoded JSON payload, in the same form as returned by exporting relations.
/// ///
@ -275,6 +278,9 @@ pub unsafe extern "C" fn cozo_restore(db_id: i32, in_path: *const c_char) -> *mu
#[no_mangle] #[no_mangle]
/// Import data into relations from a backup /// Import data into relations from a backup
/// ///
/// Note that triggers are _not_ run for the relations, if any exists.
/// If you need to activate triggers, use queries with parameters.
///
/// `db_id`: the ID representing the database. /// `db_id`: the ID representing the database.
/// `json_payload`: a UTF-8 encoded JSON payload: `{"path": ..., "relations": [...]}` /// `json_payload`: a UTF-8 encoded JSON payload: `{"path": ..., "relations": [...]}`
/// ///

@ -76,7 +76,10 @@ class CozoDb {
async exportRelations(relations: Array<string>): object; async exportRelations(relations: Array<string>): object;
/** /**
* Import several relations * Import several relations.
*
* Note that triggers are _not_ run for the relations, if any exists.
* If you need to activate triggers, use queries with parameters.
* *
* @param data: in the same form as returned by `exportRelations`. The relations * @param data: in the same form as returned by `exportRelations`. The relations
* must already exist in the database. * must already exist in the database.
@ -100,6 +103,9 @@ class CozoDb {
/** /**
* Import several relations from a backup. The relations must already exist in the database. * Import several relations from a backup. The relations must already exist in the database.
* *
* Note that triggers are _not_ run for the relations, if any exists.
* If you need to activate triggers, use queries with parameters.
*
* @param path: path to the backup file. * @param path: path to the backup file.
* @param rels: the relations to import. * @param rels: the relations to import.
*/ */

@ -110,6 +110,9 @@ public class CozoDB {
/** /**
* Import data into relations * Import data into relations
* *
* Note that triggers are _not_ run for the relations, if any exists.
* If you need to activate triggers, use queries with parameters.
*
* `data`: the payload, in the same format as returned by `exportRelations`. * `data`: the payload, in the same format as returned by `exportRelations`.
*/ */
public func importRelations(data: JSON) throws; public func importRelations(data: JSON) throws;
@ -129,7 +132,10 @@ public class CozoDB {
public func restore(path: String) throws; public func restore(path: String) throws;
/** /**
* Import data into a relation * Import data into a relation from a backup.
*
* Note that triggers are _not_ run for the relations, if any exists.
* If you need to activate triggers, use queries with parameters.
* *
* `path`: path of the input file. * `path`: path of the input file.
* `relations`: the stored relations to import into. * `relations`: the stored relations to import into.

@ -51,6 +51,8 @@ export class CozoDb {
export_relations(data: string): string; export_relations(data: string): string;
// Note that triggers are _not_ run for the relations, if any exists.
// If you need to activate triggers, use queries with parameters.
import_relations(data: string): string; import_relations(data: string): string;
} }
``` ```

@ -74,6 +74,10 @@ and a nicely-formatted diagnostic will be in `"display"` if available.
* `GET /`, if you open this in your browser and open your developer tools, you will be able to use * `GET /`, if you open this in your browser and open your developer tools, you will be able to use
a very simple client to query this database. a very simple client to query this database.
> For `import` and `import-from-backup`, triggers are _not_ run for the relations, if any exists.
If you need to activate triggers, use queries with parameters.
## Building ## Building
Building `cozo-node` requires a [Rust toolchain](https://rustup.rs). Run Building `cozo-node` requires a [Rust toolchain](https://rustup.rs). Run

Loading…
Cancel
Save