|
|
@ -231,11 +231,23 @@ impl NamedRows {
|
|
|
|
next: None,
|
|
|
|
next: None,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a query and parameters to apply an operation (insert, put, delete, rm) to a stored
|
|
|
|
|
|
|
|
/// relation with the named rows.
|
|
|
|
|
|
|
|
pub fn into_payload(self, relation: &str, op: &str) -> Payload {
|
|
|
|
|
|
|
|
let cols_str = self.headers.join(", ");
|
|
|
|
|
|
|
|
let query = format!("?[{cols_str}] <- $data :{op} {relation} {{ {cols_str} }}");
|
|
|
|
|
|
|
|
let data = DataValue::List(self.rows.into_iter().map(|r| DataValue::List(r)).collect());
|
|
|
|
|
|
|
|
(query, [("data".to_string(), data)].into())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const STATUS_STR: &str = "status";
|
|
|
|
const STATUS_STR: &str = "status";
|
|
|
|
const OK_STR: &str = "OK";
|
|
|
|
const OK_STR: &str = "OK";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The query and parameters.
|
|
|
|
|
|
|
|
pub type Payload = (String, BTreeMap<String, DataValue>);
|
|
|
|
|
|
|
|
|
|
|
|
/// Commands to be sent to a multi-transaction
|
|
|
|
/// Commands to be sent to a multi-transaction
|
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
|
|
|
pub enum TransactionPayload {
|
|
|
|
pub enum TransactionPayload {
|
|
|
@ -244,7 +256,7 @@ pub enum TransactionPayload {
|
|
|
|
/// Abort the current transaction
|
|
|
|
/// Abort the current transaction
|
|
|
|
Abort,
|
|
|
|
Abort,
|
|
|
|
/// Run a query inside the transaction
|
|
|
|
/// Run a query inside the transaction
|
|
|
|
Query((String, BTreeMap<String, DataValue>)),
|
|
|
|
Query(Payload),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
impl<'s, S: Storage<'s>> Db<S> {
|
|
|
@ -397,6 +409,7 @@ impl<'s, S: Storage<'s>> Db<S> {
|
|
|
|
mutability == ScriptMutability::Immutable,
|
|
|
|
mutability == ScriptMutability::Immutable,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Run the CozoScript passed in. The `params` argument is a map of parameters.
|
|
|
|
/// Run the CozoScript passed in. The `params` argument is a map of parameters.
|
|
|
|
pub fn run_script_read_only(
|
|
|
|
pub fn run_script_read_only(
|
|
|
|
&'s self,
|
|
|
|
&'s self,
|
|
|
|