Don’t clone variables when processing sub-contexts

Closes SUR-53

When creating a new context for subqueries or statement clauses, we used to have to clone any variables/values, and freeze the context, so that it could be used across threads and async boundaries.

Now with the new executor pattern for parallel queries, we can pass references instead, improving performance by removing unnecessary cloning of values.
This commit is contained in:
Tobie Morgan Hitchcock 2022-05-14 13:35:08 +01:00
parent f414198fad
commit 1017e2fffb
84 changed files with 376 additions and 435 deletions

View file

@ -1,32 +1,45 @@
use crate::ctx::canceller::Canceller;
use crate::ctx::reason::Reason;
use std::any::Any;
use crate::sql::value::Value;
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::{Duration, Instant};
pub struct Context {
impl<'a> From<Value> for Cow<'a, Value> {
fn from(v: Value) -> Cow<'a, Value> {
Cow::Owned(v)
}
}
impl<'a> From<&'a Value> for Cow<'a, Value> {
fn from(v: &'a Value) -> Cow<'a, Value> {
Cow::Borrowed(v)
}
}
pub struct Context<'a> {
// An optional parent context.
parent: Option<Arc<Context>>,
parent: Option<&'a Context<'a>>,
// An optional deadline.
deadline: Option<Instant>,
// Wether or not this context is cancelled.
cancelled: Arc<AtomicBool>,
// A collection of read only values stored in this context.
values: Option<HashMap<String, Box<dyn Any + Send + Sync>>>,
values: Option<HashMap<String, Cow<'a, Value>>>,
}
impl Default for Context {
impl<'a> Default for Context<'a> {
fn default() -> Self {
Context::background()
}
}
impl Context {
impl<'a> Context<'a> {
// Create an empty background context.
pub fn background() -> Context {
pub fn background() -> Self {
Context {
values: None,
parent: None,
@ -36,24 +49,15 @@ impl Context {
}
// Create a new child from a frozen context.
pub fn new(parent: &Arc<Context>) -> Context {
pub fn new(parent: &'a Context) -> Self {
Context {
values: None,
parent: Some(Arc::clone(parent)),
parent: Some(parent),
deadline: parent.deadline,
cancelled: Arc::new(AtomicBool::new(false)),
}
}
// Freeze the context so it can be used to create child contexts. The
// parent context can no longer be modified once it has been frozen.
pub fn freeze(mut self) -> Arc<Context> {
if let Some(ref mut values) = self.values {
values.shrink_to_fit();
}
Arc::new(self)
}
// Add cancelation to the context. The value that is returned will cancel
// the context and it's children once called.
pub fn add_cancel(&mut self) -> Canceller {
@ -80,10 +84,10 @@ impl Context {
// with the same key.
pub fn add_value<V>(&mut self, key: String, value: V)
where
V: Any + Send + Sync + Sized,
V: Into<Cow<'a, Value>>,
{
if let Some(ref mut values) = self.values {
values.insert(key, Box::new(value));
values.insert(key, value.into());
} else {
self.values = Some(HashMap::new());
self.add_value(key, value);
@ -104,7 +108,7 @@ impl Context {
// TODO: see if we can relax the ordering.
_ if self.cancelled.load(Ordering::SeqCst) => Some(Reason::Canceled),
_ => match self.parent {
Some(ref parent_ctx) => parent_ctx.done(),
Some(ctx) => ctx.done(),
_ => None,
},
}
@ -146,24 +150,27 @@ impl Context {
// Get a value from the context. If no value is stored under the
// provided key, then this will return None.
pub fn value<V>(&self, key: &str) -> Option<&V>
where
V: Any + Send + Sync + Sized,
{
if let Some(ref values) = self.values {
if let Some(value) = values.get(key) {
let value: &dyn Any = &**value;
return value.downcast_ref::<V>();
}
}
match self.parent {
Some(ref parent) => parent.value(key),
pub fn value(&self, key: &str) -> Option<&Value> {
match &self.values {
Some(v) => match v.get(key) {
Some(v) => match v {
Cow::Borrowed(v) => Some(*v),
Cow::Owned(v) => Some(v),
},
None => match self.parent {
Some(p) => p.value(key),
_ => None,
},
},
None => match self.parent {
Some(p) => p.value(key),
_ => None,
},
}
}
}
impl fmt::Debug for Context {
impl<'a> fmt::Debug for Context<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Context")
.field("parent", &self.parent)

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::err::Error;
@ -16,7 +16,7 @@ use channel::Sender;
impl Value {
pub(crate) async fn channel(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -39,7 +39,7 @@ impl Array {
#[async_recursion]
pub(crate) async fn process(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -63,7 +63,7 @@ impl Array {
impl Model {
pub(crate) async fn process(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -100,7 +100,7 @@ impl Model {
impl Thing {
pub(crate) async fn process(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,
@ -122,7 +122,7 @@ impl Thing {
impl Table {
pub(crate) async fn process(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -3,7 +3,6 @@ use crate::dbs::response::Response;
use crate::dbs::Auth;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::kvs::Datastore;
@ -117,7 +116,7 @@ impl<'a> Executor<'a> {
pub async fn execute(
&mut self,
mut ctx: Runtime,
mut ctx: Context<'_>,
mut opt: Options,
qry: Query,
) -> Result<Vec<Response>, Error> {
@ -213,10 +212,7 @@ impl<'a> Executor<'a> {
// Process the statement
match stm.compute(&ctx, &opt, &self.txn(), None).await {
Ok(val) => {
let mut new = Context::new(&ctx);
let key = stm.name.to_owned();
new.add_value(key, val);
ctx = new.freeze();
ctx.add_value(stm.name.to_owned(), val);
}
_ => break,
}
@ -240,7 +236,6 @@ impl<'a> Executor<'a> {
// Set statement timeout
let mut ctx = Context::new(&ctx);
ctx.add_timeout(timeout);
let ctx = ctx.freeze();
// Process the statement
let res = stm.compute(&ctx, &opt, &self.txn(), None).await;
// Catch statement timeout

View file

@ -1,6 +1,6 @@
use crate::ctx::Context;
use crate::dbs::Iterator;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::err::Error;
@ -18,7 +18,7 @@ impl Value {
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
pub(crate) async fn iterate(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -42,7 +42,7 @@ impl Array {
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
pub(crate) async fn iterate(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -66,7 +66,7 @@ impl Array {
impl Model {
pub(crate) async fn iterate(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -103,7 +103,7 @@ impl Model {
impl Thing {
pub(crate) async fn iterate(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -125,7 +125,7 @@ impl Thing {
impl Table {
pub(crate) async fn iterate(
self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -2,7 +2,6 @@ use crate::cnf::MAX_CONCURRENT_TASKS;
use crate::ctx::Canceller;
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -54,7 +53,7 @@ impl Iterator {
// Process the records and output
pub async fn output(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -64,7 +63,6 @@ impl Iterator {
// Enable context override
let mut ctx = Context::new(ctx);
self.run = ctx.add_cancel();
let ctx = ctx.freeze();
// Process prepared values
self.iterate(&ctx, opt, txn, stm).await?;
// Return any document errors
@ -90,7 +88,7 @@ impl Iterator {
#[inline]
async fn output_split(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -134,7 +132,7 @@ impl Iterator {
#[inline]
async fn output_group(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -217,7 +215,7 @@ impl Iterator {
#[inline]
async fn output_order(
&mut self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
stm: &Statement<'_>,
@ -256,7 +254,7 @@ impl Iterator {
#[inline]
async fn output_start(
&mut self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
stm: &Statement<'_>,
@ -270,7 +268,7 @@ impl Iterator {
#[inline]
async fn output_limit(
&mut self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
stm: &Statement<'_>,
@ -284,7 +282,7 @@ impl Iterator {
#[inline]
async fn output_fetch(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -323,7 +321,7 @@ impl Iterator {
#[cfg(not(feature = "parallel"))]
async fn iterate(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -339,7 +337,7 @@ impl Iterator {
#[cfg(feature = "parallel")]
async fn iterate(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -412,7 +410,7 @@ impl Iterator {
// Process a new record Thing and Value
pub async fn process(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -4,7 +4,6 @@ mod iterate;
mod iterator;
mod options;
mod response;
mod runtime;
mod session;
mod statement;
mod transaction;
@ -15,7 +14,6 @@ pub use self::executor::*;
pub use self::iterator::*;
pub use self::options::*;
pub use self::response::*;
pub use self::runtime::*;
pub use self::session::*;
pub use self::statement::*;
pub use self::transaction::*;

View file

@ -1,25 +0,0 @@
/*
* A Runtime is passed around when processing a set of query
* statements. The Runtime contains any saved parameters and
* variables set in the SQL, or any pre-defined paramaters which
* are determined by the authentication / session / environment.
* Embedded queries, and subqueries will create their own Runtime
* based off of the parent Runtime, and set their own variables
* accordingly. Predetermined variables include:
*
* $ENV = "surrealdb.com";
*
* $auth.AL = "KV" / "NS" / "DB" / "SC";
* $auth.NS = "";
* $auth.DB = "";
*
* $session.id = "";
* $session.ip = "";
* $session.origin = "app.surrealdb.com";
*
*/
use crate::ctx::Context;
use std::sync::Arc;
pub type Runtime = Arc<Context>;

View file

@ -34,7 +34,7 @@ impl Session {
self.db.to_owned().map(Arc::new)
}
// Convert a session into a runtime
pub(crate) fn context(&self, mut ctx: Context) -> Context {
pub(crate) fn context<'a>(&self, mut ctx: Context<'a>) -> Context<'a> {
// Add session value
let key = String::from("session");
let val: Value = self.into();

View file

@ -1,13 +1,12 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::kvs::Datastore;
use futures::lock::Mutex;
use std::sync::Arc;
pub async fn mock<'a>() -> (Runtime, Options, Transaction) {
let ctx = Context::default().freeze();
pub async fn mock<'a>() -> (Context<'a>, Options, Transaction) {
let ctx = Context::default();
let opt = Options::default();
let kvs = Datastore::new("memory").await.unwrap();
let txn = kvs.transaction(true, false).await.unwrap();

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn admit(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -9,7 +9,7 @@ use crate::sql::permission::Permission;
impl<'a> Document<'a> {
pub async fn allow(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn check(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -10,7 +10,7 @@ use channel::Sender;
impl<'a> Document<'a> {
pub(crate) async fn compute(
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn create(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn delete(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn empty(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn erase(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,6 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -11,7 +10,7 @@ use std::ops::Deref;
impl<'a> Document<'a> {
pub async fn event(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,
@ -37,10 +36,9 @@ impl<'a> Document<'a> {
// Configure the context
let mut ctx = Context::new(ctx);
ctx.add_value("event".into(), met);
ctx.add_value("value".into(), self.current.deref().clone());
ctx.add_value("after".into(), self.current.deref().clone());
ctx.add_value("before".into(), self.initial.deref().clone());
let ctx = ctx.freeze();
ctx.add_value("value".into(), self.current.deref());
ctx.add_value("after".into(), self.current.deref());
ctx.add_value("before".into(), self.initial.deref());
// Ensure event queries run
let opt = &opt.perms(false);
// Process conditional clause

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn exist(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,6 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -11,7 +10,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn field(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,
@ -28,10 +27,9 @@ impl<'a> Document<'a> {
if let Some(expr) = &fd.value {
// Configure the context
let mut ctx = Context::new(ctx);
ctx.add_value("value".into(), val.clone());
ctx.add_value("after".into(), val.clone());
ctx.add_value("before".into(), old.clone());
let ctx = ctx.freeze();
ctx.add_value("value".into(), &val);
ctx.add_value("after".into(), &val);
ctx.add_value("before".into(), &old);
// Process the VALUE clause
val = expr.compute(&ctx, opt, txn, Some(&self.current)).await?;
}
@ -43,10 +41,9 @@ impl<'a> Document<'a> {
if let Some(expr) = &fd.assert {
// Configure the context
let mut ctx = Context::new(ctx);
ctx.add_value("value".into(), val.clone());
ctx.add_value("after".into(), val.clone());
ctx.add_value("before".into(), old.clone());
let ctx = ctx.freeze();
ctx.add_value("value".into(), &val);
ctx.add_value("after".into(), &val);
ctx.add_value("before".into(), &old);
// Process the ASSERT clause
if !expr.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
return Err(Error::FieldValue {
@ -73,10 +70,9 @@ impl<'a> Document<'a> {
Permission::Specific(e) => {
// Configure the context
let mut ctx = Context::new(ctx);
ctx.add_value("value".into(), val.clone());
ctx.add_value("after".into(), val.clone());
ctx.add_value("before".into(), old.clone());
let ctx = ctx.freeze();
ctx.add_value("value".into(), &val);
ctx.add_value("after".into(), &val);
ctx.add_value("before".into(), &old);
// Process the PERMISSION clause
if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
val = old

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -9,7 +9,7 @@ use crate::sql::array::Array;
impl<'a> Document<'a> {
pub async fn index(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn insert(
&mut self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn lives(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -11,7 +11,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn merge(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,6 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -14,7 +13,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn pluck(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,
@ -127,8 +126,7 @@ impl<'a> Document<'a> {
let val = self.current.pick(k);
// Configure the context
let mut ctx = Context::new(ctx);
ctx.add_value("value".into(), val);
let ctx = ctx.freeze();
ctx.add_value("value".into(), &val);
// Process the PERMISSION clause
if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
out.del(&ctx, opt, txn, k).await?

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn purge(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn relate(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn select(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn store(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -8,7 +8,7 @@ use crate::err::Error;
impl<'a> Document<'a> {
pub async fn table(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
_stm: &Statement<'_>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::doc::Document;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl<'a> Document<'a> {
pub async fn update(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
stm: &Statement<'_>,

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
@ -15,11 +15,11 @@ pub enum Args {
}
pub fn check(
ctx: &Runtime,
ctx: &Context,
name: &str,
args: Vec<Value>,
size: Args,
func: fn(&Runtime, Vec<Value>) -> Result<Value, Error>,
func: fn(&Context, Vec<Value>) -> Result<Value, Error>,
) -> Result<Value, Error> {
match size {
Args::None => match args.len() {

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::array::Combine;
use crate::sql::array::Concat;
@ -8,7 +8,7 @@ use crate::sql::array::Union;
use crate::sql::array::Uniq;
use crate::sql::value::Value;
pub fn concat(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn concat(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => match args.remove(0) {
Value::Array(w) => Ok(v.concat(w).into()),
@ -18,7 +18,7 @@ pub fn concat(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn combine(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn combine(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => match args.remove(0) {
Value::Array(w) => Ok(v.combine(w).into()),
@ -28,7 +28,7 @@ pub fn combine(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn difference(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn difference(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => match args.remove(0) {
Value::Array(w) => Ok(v.difference(w).into()),
@ -38,14 +38,14 @@ pub fn difference(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn distinct(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn distinct(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.uniq().into()),
_ => Ok(Value::None),
}
}
pub fn intersect(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn intersect(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => match args.remove(0) {
Value::Array(w) => Ok(v.intersect(w).into()),
@ -55,14 +55,14 @@ pub fn intersect(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn len(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn len(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.len().into()),
_ => Ok(Value::None),
}
}
pub fn union(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn union(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => match args.remove(0) {
Value::Array(w) => Ok(v.union(w).into()),

View file

@ -1,9 +1,9 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::number::Number;
use crate::sql::value::Value;
pub fn run(ctx: &Runtime, name: &str, val: Value) -> Result<Value, Error> {
pub fn run(ctx: &Context, name: &str, val: Value) -> Result<Value, Error> {
match name {
"bool" => bool(ctx, val),
"int" => int(ctx, val),
@ -17,56 +17,56 @@ pub fn run(ctx: &Runtime, name: &str, val: Value) -> Result<Value, Error> {
}
}
pub fn bool(_: &Runtime, val: Value) -> Result<Value, Error> {
pub fn bool(_: &Context, val: Value) -> Result<Value, Error> {
match val.is_truthy() {
true => Ok(Value::True),
false => Ok(Value::False),
}
}
pub fn int(_: &Runtime, val: Value) -> Result<Value, Error> {
pub fn int(_: &Context, val: Value) -> Result<Value, Error> {
match val {
Value::Number(Number::Int(_)) => Ok(val),
_ => Ok(Value::Number(Number::Int(val.as_int()))),
}
}
pub fn float(_: &Runtime, val: Value) -> Result<Value, Error> {
pub fn float(_: &Context, val: Value) -> Result<Value, Error> {
match val {
Value::Number(Number::Float(_)) => Ok(val),
_ => Ok(Value::Number(Number::Float(val.as_float()))),
}
}
pub fn number(_: &Runtime, val: Value) -> Result<Value, Error> {
pub fn number(_: &Context, val: Value) -> Result<Value, Error> {
match val {
Value::Number(Number::Decimal(_)) => Ok(val),
_ => Ok(Value::Number(Number::Decimal(val.as_decimal()))),
}
}
pub fn decimal(_: &Runtime, val: Value) -> Result<Value, Error> {
pub fn decimal(_: &Context, val: Value) -> Result<Value, Error> {
match val {
Value::Number(Number::Decimal(_)) => Ok(val),
_ => Ok(Value::Number(Number::Decimal(val.as_decimal()))),
}
}
pub fn string(_: &Runtime, val: Value) -> Result<Value, Error> {
pub fn string(_: &Context, val: Value) -> Result<Value, Error> {
match val {
Value::Strand(_) => Ok(val),
_ => Ok(Value::Strand(val.as_strand())),
}
}
pub fn datetime(_: &Runtime, val: Value) -> Result<Value, Error> {
pub fn datetime(_: &Context, val: Value) -> Result<Value, Error> {
match val {
Value::Datetime(_) => Ok(val),
_ => Ok(Value::Datetime(val.as_datetime())),
}
}
pub fn duration(_: &Runtime, val: Value) -> Result<Value, Error> {
pub fn duration(_: &Context, val: Value) -> Result<Value, Error> {
match val {
Value::Duration(_) => Ok(val),
_ => Ok(Value::Duration(val.as_duration())),

View file

@ -1,8 +1,8 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
pub fn count(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn count(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
1 => match args.remove(0) {
Value::Array(v) => Ok(v.iter().filter(|v| v.is_truthy()).count().into()),

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
use md5::Digest;
@ -7,7 +7,7 @@ use sha1::Sha1;
use sha2::Sha256;
use sha2::Sha512;
pub fn md5(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn md5(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let mut hasher = Md5::new();
hasher.update(args.remove(0).as_string().as_str());
let val = hasher.finalize();
@ -15,7 +15,7 @@ pub fn md5(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(val.into())
}
pub fn sha1(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn sha1(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let mut hasher = Sha1::new();
hasher.update(args.remove(0).as_string().as_str());
let val = hasher.finalize();
@ -23,7 +23,7 @@ pub fn sha1(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(val.into())
}
pub fn sha256(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn sha256(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let mut hasher = Sha256::new();
hasher.update(args.remove(0).as_string().as_str());
let val = hasher.finalize();
@ -31,7 +31,7 @@ pub fn sha256(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(val.into())
}
pub fn sha512(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn sha512(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let mut hasher = Sha512::new();
hasher.update(args.remove(0).as_string().as_str());
let val = hasher.finalize();
@ -41,7 +41,7 @@ pub fn sha512(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub mod argon2 {
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
use argon2::{
@ -50,7 +50,7 @@ pub mod argon2 {
};
use rand::rngs::OsRng;
pub fn cmp(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn cmp(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let algo = Argon2::default();
let hash = args.remove(0).as_string();
let pass = args.remove(0).as_string();
@ -58,7 +58,7 @@ pub mod argon2 {
Ok(algo.verify_password(pass.as_ref(), &test).is_ok().into())
}
pub fn gen(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn gen(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let algo = Argon2::default();
let pass = args.remove(0).as_string();
let salt = SaltString::generate(&mut OsRng);
@ -69,7 +69,7 @@ pub mod argon2 {
pub mod pbkdf2 {
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
use pbkdf2::{
@ -78,14 +78,14 @@ pub mod pbkdf2 {
};
use rand::rngs::OsRng;
pub fn cmp(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn cmp(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let hash = args.remove(0).as_string();
let pass = args.remove(0).as_string();
let test = PasswordHash::new(&hash).unwrap();
Ok(Pbkdf2.verify_password(pass.as_ref(), &test).is_ok().into())
}
pub fn gen(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn gen(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let pass = args.remove(0).as_string();
let salt = SaltString::generate(&mut OsRng);
let hash = Pbkdf2.hash_password(pass.as_ref(), salt.as_ref()).unwrap().to_string();
@ -95,7 +95,7 @@ pub mod pbkdf2 {
pub mod scrypt {
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
use rand::rngs::OsRng;
@ -104,14 +104,14 @@ pub mod scrypt {
Scrypt,
};
pub fn cmp(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn cmp(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let hash = args.remove(0).as_string();
let pass = args.remove(0).as_string();
let test = PasswordHash::new(&hash).unwrap();
Ok(Scrypt.verify_password(pass.as_ref(), &test).is_ok().into())
}
pub fn gen(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn gen(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let pass = args.remove(0).as_string();
let salt = SaltString::generate(&mut OsRng);
let hash = Scrypt.hash_password(pass.as_ref(), salt.as_ref()).unwrap().to_string();

View file

@ -1,7 +1,7 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
pub fn run(_: &Runtime, expr: Value) -> Result<Value, Error> {
pub fn run(_: &Context, expr: Value) -> Result<Value, Error> {
Ok(expr)
}

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::geometry::Geometry;
use crate::sql::value::Value;
@ -7,7 +7,7 @@ use geo::algorithm::bearing::Bearing;
use geo::algorithm::centroid::Centroid;
use geo::algorithm::haversine_distance::HaversineDistance;
pub fn area(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn area(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Geometry(v) => match v {
Geometry::Point(v) => Ok(v.signed_area().into()),
@ -24,7 +24,7 @@ pub fn area(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn bearing(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn bearing(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Geometry(Geometry::Point(v)) => match args.remove(0) {
Value::Geometry(Geometry::Point(w)) => Ok(v.bearing(w).into()),
@ -34,7 +34,7 @@ pub fn bearing(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn centroid(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn centroid(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Geometry(v) => match v {
Geometry::Point(v) => Ok(v.centroid().into()),
@ -69,7 +69,7 @@ pub fn centroid(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn distance(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn distance(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Geometry(Geometry::Point(v)) => match args.remove(0) {
Value::Geometry(Geometry::Point(w)) => Ok(v.haversine_distance(&w).into()),
@ -81,13 +81,13 @@ pub fn distance(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub mod hash {
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::fnc::util::geo;
use crate::sql::geometry::Geometry;
use crate::sql::value::Value;
pub fn encode(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn encode(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
2 => match args.remove(0) {
Value::Geometry(Geometry::Point(v)) => match args.remove(0).as_int() {
@ -107,7 +107,7 @@ pub mod hash {
}
}
pub fn decode(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn decode(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Strand(v) => Ok(geo::decode(v).into()),
_ => Ok(Value::None),

View file

@ -1,8 +1,8 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
pub async fn head(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn head(_ctx: &Context<'_>, args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
1 | 2 => todo!(),
_ => Err(Error::InvalidArguments {
@ -12,7 +12,7 @@ pub async fn head(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
}
}
pub async fn get(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn get(_ctx: &Context<'_>, args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
1 | 2 => todo!(),
_ => Err(Error::InvalidArguments {
@ -22,7 +22,7 @@ pub async fn get(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
}
}
pub async fn put(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn put(_ctx: &Context<'_>, args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
1 | 2 | 3 => todo!(),
_ => Err(Error::InvalidArguments {
@ -32,7 +32,7 @@ pub async fn put(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
}
}
pub async fn post(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn post(_ctx: &Context<'_>, args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
1 | 2 | 3 => todo!(),
_ => Err(Error::InvalidArguments {
@ -42,7 +42,7 @@ pub async fn post(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
}
}
pub async fn patch(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn patch(_ctx: &Context<'_>, args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
1 | 2 | 3 => todo!(),
_ => Err(Error::InvalidArguments {
@ -52,7 +52,7 @@ pub async fn patch(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
}
}
pub async fn delete(_ctx: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub async fn delete(_ctx: &Context<'_>, args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
1 | 2 => todo!(),
_ => Err(Error::InvalidArguments {

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
use once_cell::sync::Lazy;
@ -13,23 +13,23 @@ use std::char;
#[rustfmt::skip] static LATITUDE_RE: Lazy<Regex> = Lazy::new(|| Regex::new("^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$").unwrap());
#[rustfmt::skip] static LONGITUDE_RE: Lazy<Regex> = Lazy::new(|| Regex::new("^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$").unwrap());
pub fn alphanum(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn alphanum(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().chars().all(char::is_alphanumeric).into())
}
pub fn alpha(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn alpha(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().chars().all(char::is_alphabetic).into())
}
pub fn ascii(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn ascii(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().chars().all(|x| char::is_ascii(&x)).into())
}
pub fn domain(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn domain(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(DOMAIN_RE.is_match(args.remove(0).as_string().as_str()).into())
}
pub fn email(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn email(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Convert to a &str
@ -56,26 +56,26 @@ pub fn email(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(Value::True)
}
pub fn hexadecimal(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn hexadecimal(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().chars().all(|x| char::is_ascii_hexdigit(&x)).into())
}
pub fn latitude(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn latitude(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(LATITUDE_RE.is_match(args.remove(0).as_string().as_str()).into())
}
pub fn longitude(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn longitude(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(LONGITUDE_RE.is_match(args.remove(0).as_string().as_str()).into())
}
pub fn numeric(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn numeric(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().chars().all(char::is_numeric).into())
}
pub fn semver(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn semver(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(SEMVER_RE.is_match(args.remove(0).as_string().as_str()).into())
}
pub fn uuid(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn uuid(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(UUID_RE.is_match(args.remove(0).as_string().as_str()).into())
}

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::fnc::util::math::bottom::Bottom;
use crate::fnc::util::math::deviation::Deviation;
@ -16,11 +16,11 @@ use crate::fnc::util::math::variance::Variance;
use crate::sql::number::Number;
use crate::sql::value::Value;
pub fn abs(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn abs(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_number().abs().into())
}
pub fn bottom(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn bottom(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => {
let c = args.remove(0).as_int();
@ -30,11 +30,11 @@ pub fn bottom(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn ceil(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn ceil(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_number().ceil().into())
}
pub fn fixed(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn fixed(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let v = args.remove(0);
match args.remove(0).as_int() {
p if p > 0 => Ok(v.as_number().fixed(p as usize).into()),
@ -45,18 +45,18 @@ pub fn fixed(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn floor(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn floor(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_number().floor().into())
}
pub fn interquartile(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn interquartile(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().interquartile().into()),
_ => Ok(Value::None),
}
}
pub fn max(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn max(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => match v.as_numbers().into_iter().max() {
Some(v) => Ok(v.into()),
@ -66,28 +66,28 @@ pub fn max(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn mean(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn mean(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().mean().into()),
_ => Ok(Value::None),
}
}
pub fn median(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn median(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().median().into()),
_ => Ok(Value::None),
}
}
pub fn midhinge(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn midhinge(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().midhinge().into()),
_ => Ok(Value::None),
}
}
pub fn min(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn min(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => match v.as_numbers().into_iter().min() {
Some(v) => Ok(v.into()),
@ -97,64 +97,64 @@ pub fn min(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn mode(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn mode(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().mode().into()),
_ => Ok(Value::None),
}
}
pub fn nearestrank(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn nearestrank(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().nearestrank(args.remove(0).as_number()).into()),
_ => Ok(Value::None),
}
}
pub fn percentile(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn percentile(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().percentile(args.remove(0).as_number()).into()),
_ => Ok(Value::None),
}
}
pub fn product(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn product(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().into_iter().product::<Number>().into()),
_ => Ok(Value::None),
}
}
pub fn round(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn round(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_number().round().into())
}
pub fn spread(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn spread(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().spread().into()),
_ => Ok(Value::None),
}
}
pub fn sqrt(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn sqrt(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_number().sqrt().into())
}
pub fn stddev(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn stddev(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().deviation().into()),
_ => Ok(Value::None),
}
}
pub fn sum(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn sum(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().into_iter().sum::<Number>().into()),
_ => Ok(Value::None),
}
}
pub fn top(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn top(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => {
let c = args.remove(0).as_int();
@ -164,14 +164,14 @@ pub fn top(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn trimean(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn trimean(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().trimean().into()),
_ => Ok(Value::None),
}
}
pub fn variance(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn variance(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Array(v) => Ok(v.as_numbers().variance().into()),
_ => Ok(Value::None),

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::fnc::args::Args;
use crate::sql::value::Value;
@ -22,7 +22,7 @@ pub mod time;
pub mod r#type;
pub mod util;
pub async fn run(ctx: &Runtime, name: &str, args: Vec<Value>) -> Result<Value, Error> {
pub async fn run(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Value, Error> {
match name {
//
"array::combine" => args::check(ctx, name, args, Args::Two, array::combine),

View file

@ -1,6 +1,6 @@
pub mod email {
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
use once_cell::sync::Lazy;
@ -9,7 +9,7 @@ pub mod email {
#[rustfmt::skip] static USER_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(?i)[a-z0-9.!#$%&'*+/=?^_`{|}~-]+\z").unwrap());
#[rustfmt::skip] static HOST_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$",).unwrap());
pub fn domain(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn domain(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Check if value is empty
@ -34,7 +34,7 @@ pub mod email {
Ok(parts[0].into())
}
pub fn user(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn user(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Check if value is empty
@ -62,12 +62,12 @@ pub mod email {
pub mod url {
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
use url::Url;
pub fn domain(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn domain(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Parse the URL
@ -80,7 +80,7 @@ pub mod url {
}
}
pub fn fragment(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn fragment(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Parse the URL
@ -93,7 +93,7 @@ pub mod url {
}
}
pub fn host(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn host(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Parse the URL
@ -106,7 +106,7 @@ pub mod url {
}
}
pub fn path(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn path(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Parse the URL
@ -116,7 +116,7 @@ pub mod url {
}
}
pub fn port(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn port(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Parse the URL
@ -129,7 +129,7 @@ pub mod url {
}
}
pub fn query(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn query(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
// Convert to a String
let val = args.remove(0).as_string();
// Parse the URL

View file

@ -1,5 +1,5 @@
use crate::cnf::ID_CHARS;
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::datetime::Datetime;
use crate::sql::value::Value;
@ -8,15 +8,15 @@ use rand::distributions::Alphanumeric;
use rand::Rng;
use uuid::Uuid;
pub fn rand(_: &Runtime, _: Vec<Value>) -> Result<Value, Error> {
pub fn rand(_: &Context, _: Vec<Value>) -> Result<Value, Error> {
Ok(rand::random::<f64>().into())
}
pub fn bool(_: &Runtime, _: Vec<Value>) -> Result<Value, Error> {
pub fn bool(_: &Context, _: Vec<Value>) -> Result<Value, Error> {
Ok(rand::random::<bool>().into())
}
pub fn r#enum(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn r#enum(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Value::None),
1 => match args.remove(0) {
@ -36,7 +36,7 @@ pub fn r#enum(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn float(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn float(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
2 => {
let min = args.remove(0).as_float();
@ -50,7 +50,7 @@ pub fn float(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn guid(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn guid(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
1 => {
let len = args.remove(0).as_int() as usize;
@ -61,7 +61,7 @@ pub fn guid(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn int(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn int(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
2 => {
let min = args.remove(0).as_int();
@ -75,7 +75,7 @@ pub fn int(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn string(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn string(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
2 => match args.remove(0).as_int() {
min if min >= 0 => match args.remove(0).as_int() {
@ -123,7 +123,7 @@ pub fn string(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn time(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn time(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
2 => {
let min = args.remove(0).as_int();
@ -146,6 +146,6 @@ pub fn time(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn uuid(_: &Runtime, _: Vec<Value>) -> Result<Value, Error> {
pub fn uuid(_: &Context, _: Vec<Value>) -> Result<Value, Error> {
Ok(Uuid::new_v4().to_string().into())
}

View file

@ -1,9 +1,9 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::script::Script;
use crate::sql::value::Value;
pub fn run(_ctx: &Runtime, _expr: Script) -> Result<Value, Error> {
pub fn run(_ctx: &Context, _expr: Script) -> Result<Value, Error> {
Err(Error::InvalidScript {
message: String::from("Embedded functions are not yet supported."),
})

View file

@ -1,53 +1,53 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::value::Value;
use slug::slugify;
pub fn concat(_: &Runtime, args: Vec<Value>) -> Result<Value, Error> {
pub fn concat(_: &Context, args: Vec<Value>) -> Result<Value, Error> {
Ok(args.into_iter().map(|x| x.as_string()).collect::<Vec<_>>().concat().into())
}
pub fn ends_with(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn ends_with(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0).as_string();
let chr = args.remove(0).as_string();
Ok(val.ends_with(&chr).into())
}
pub fn join(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn join(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let chr = args.remove(0).as_string();
let val = args.into_iter().map(|x| x.as_string());
let val = val.collect::<Vec<_>>().join(&chr);
Ok(val.into())
}
pub fn length(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn length(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0).as_string();
let num = val.chars().count() as i64;
Ok(num.into())
}
pub fn lowercase(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn lowercase(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().to_lowercase().into())
}
pub fn repeat(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn repeat(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0).as_string();
let num = args.remove(0).as_int() as usize;
Ok(val.repeat(num).into())
}
pub fn replace(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn replace(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0).as_string();
let old = args.remove(0).as_string();
let new = args.remove(0).as_string();
Ok(val.replace(&old, &new).into())
}
pub fn reverse(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn reverse(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().chars().rev().collect::<String>().into())
}
pub fn slice(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn slice(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0).as_string();
let beg = args.remove(0).as_int() as usize;
let lim = args.remove(0).as_int() as usize;
@ -55,31 +55,31 @@ pub fn slice(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(val.into())
}
pub fn slug(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn slug(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(slugify(&args.remove(0).as_string()).into())
}
pub fn split(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn split(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0).as_string();
let chr = args.remove(0).as_string();
let val = val.split(&chr).collect::<Vec<&str>>();
Ok(val.into())
}
pub fn starts_with(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn starts_with(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0).as_string();
let chr = args.remove(0).as_string();
Ok(val.starts_with(&chr).into())
}
pub fn trim(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn trim(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().trim().into())
}
pub fn uppercase(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn uppercase(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().to_uppercase().into())
}
pub fn words(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn words(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(args.remove(0).as_string().split(' ').collect::<Vec<&str>>().into())
}

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::datetime::Datetime;
use crate::sql::value::Value;
@ -8,7 +8,7 @@ use chrono::DurationRound;
use chrono::Timelike;
use chrono::Utc;
pub fn day(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn day(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().day().into()),
_ => match args.remove(0) {
@ -18,7 +18,7 @@ pub fn day(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn floor(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn floor(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Datetime(v) => match args.remove(0) {
Value::Duration(w) => match chrono::Duration::from_std(*w) {
@ -34,7 +34,7 @@ pub fn floor(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn group(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn group(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Datetime(v) => match args.remove(0) {
Value::Strand(g) => match g.as_str() {
@ -67,7 +67,7 @@ pub fn group(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn hour(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn hour(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().hour().into()),
_ => match args.remove(0) {
@ -77,7 +77,7 @@ pub fn hour(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn mins(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn mins(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().minute().into()),
_ => match args.remove(0) {
@ -87,7 +87,7 @@ pub fn mins(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn month(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn month(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().day().into()),
_ => match args.remove(0) {
@ -97,7 +97,7 @@ pub fn month(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn nano(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn nano(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().timestamp_nanos().into()),
_ => match args.remove(0) {
@ -107,11 +107,11 @@ pub fn nano(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn now(_: &Runtime, _: Vec<Value>) -> Result<Value, Error> {
pub fn now(_: &Context, _: Vec<Value>) -> Result<Value, Error> {
Ok(Datetime::default().into())
}
pub fn round(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn round(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Datetime(v) => match args.remove(0) {
Value::Duration(w) => match chrono::Duration::from_std(*w) {
@ -127,7 +127,7 @@ pub fn round(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn secs(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn secs(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().second().into()),
_ => match args.remove(0) {
@ -137,7 +137,7 @@ pub fn secs(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn unix(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn unix(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().timestamp().into()),
_ => match args.remove(0) {
@ -147,7 +147,7 @@ pub fn unix(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn wday(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn wday(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().weekday().number_from_monday().into()),
_ => match args.remove(0) {
@ -157,7 +157,7 @@ pub fn wday(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn week(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn week(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().iso_week().week().into()),
_ => match args.remove(0) {
@ -167,7 +167,7 @@ pub fn week(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn yday(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn yday(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().ordinal().into()),
_ => match args.remove(0) {
@ -177,7 +177,7 @@ pub fn yday(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn year(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn year(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
0 => Ok(Utc::now().year().into()),
_ => match args.remove(0) {

View file

@ -1,4 +1,4 @@
use crate::dbs::Runtime;
use crate::ctx::Context;
use crate::err::Error;
use crate::sql::geometry::Geometry;
use crate::sql::number::Number;
@ -6,14 +6,14 @@ use crate::sql::table::Table;
use crate::sql::thing::Thing;
use crate::sql::value::Value;
pub fn bool(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn bool(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0).is_truthy() {
true => Ok(Value::True),
false => Ok(Value::False),
}
}
pub fn datetime(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn datetime(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0);
match val {
Value::Datetime(_) => Ok(val),
@ -21,7 +21,7 @@ pub fn datetime(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn decimal(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn decimal(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0);
match val {
Value::Number(Number::Decimal(_)) => Ok(val),
@ -29,7 +29,7 @@ pub fn decimal(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn duration(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn duration(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0);
match val {
Value::Duration(_) => Ok(val),
@ -37,7 +37,7 @@ pub fn duration(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn float(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn float(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0);
match val {
Value::Number(Number::Float(_)) => Ok(val),
@ -45,7 +45,7 @@ pub fn float(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn int(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn int(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0);
match val {
Value::Number(Number::Int(_)) => Ok(val),
@ -53,7 +53,7 @@ pub fn int(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn number(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn number(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0);
match val {
Value::Number(_) => Ok(val),
@ -61,7 +61,7 @@ pub fn number(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn point(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn point(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.len() {
2 => {
let x = args.remove(0);
@ -77,14 +77,14 @@ pub fn point(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn regex(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn regex(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
match args.remove(0) {
Value::Strand(v) => Ok(Value::Regex(v.as_str().into())),
_ => Ok(Value::None),
}
}
pub fn string(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn string(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let val = args.remove(0);
match val {
Value::Strand(_) => Ok(val),
@ -92,11 +92,11 @@ pub fn string(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
}
}
pub fn table(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn table(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
Ok(Value::Table(Table(args.remove(0).as_string())))
}
pub fn thing(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
pub fn thing(_: &Context, mut args: Vec<Value>) -> Result<Value, Error> {
let tb = args.remove(0);
match args.remove(0) {
Value::Thing(id) => Ok(Value::Thing(Thing {

View file

@ -163,8 +163,6 @@ impl Datastore {
let ctx = vars.attach(ctx);
// Parse the SQL query text
let ast = sql::parse(txt)?;
// Freeze the context
let ctx = ctx.freeze();
// Process all statements
opt.auth = sess.au.clone();
opt.ns = sess.ns();
@ -189,8 +187,6 @@ impl Datastore {
let ctx = sess.context(ctx);
// Store the query variables
let ctx = vars.attach(ctx);
// Freeze the context
let ctx = ctx.freeze();
// Process all statements
opt.auth = sess.au.clone();
opt.ns = sess.ns();

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::mightbespace;
@ -132,7 +132,7 @@ impl Array {
impl Array {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::fnc;
@ -59,7 +59,7 @@ impl Expression {
impl Expression {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::fnc;
@ -104,7 +104,7 @@ impl Function {
impl Function {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::common::commas;
@ -72,7 +72,7 @@ impl Idiom {
impl Idiom {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::mightbespace;
@ -100,7 +100,7 @@ impl Object {
impl Object {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::error::IResult;
@ -33,7 +33,7 @@ impl Deref for Param {
impl Param {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,
@ -55,7 +55,7 @@ impl Param {
// The base document does not exist
None => Ok(Value::None),
},
_ => match ctx.value::<Value>(v) {
_ => match ctx.value(v) {
// The base variable exists
Some(v) => {
// Get the path parts

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::{comment, mightbespace};
@ -97,7 +97,7 @@ impl Statement {
impl Statement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,7 +1,7 @@
use crate::ctx::Context;
use crate::dbs::Iterator;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::err::Error;
@ -30,7 +30,7 @@ pub struct CreateStatement {
impl CreateStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,6 +1,6 @@
use crate::ctx::Context;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::algorithm::{algorithm, Algorithm};
@ -48,7 +48,7 @@ pub enum DefineStatement {
impl DefineStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,
@ -109,7 +109,7 @@ pub struct DefineNamespaceStatement {
impl DefineNamespaceStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -156,7 +156,7 @@ pub struct DefineDatabaseStatement {
impl DefineDatabaseStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -211,7 +211,7 @@ pub struct DefineLoginStatement {
impl DefineLoginStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -330,7 +330,7 @@ pub struct DefineTokenStatement {
impl DefineTokenStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -426,7 +426,7 @@ pub struct DefineScopeStatement {
impl DefineScopeStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -562,7 +562,7 @@ pub struct DefineTableStatement {
impl DefineTableStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,
@ -727,7 +727,7 @@ pub struct DefineEventStatement {
impl DefineEventStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -806,7 +806,7 @@ pub struct DefineFieldStatement {
impl DefineFieldStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -944,7 +944,7 @@ pub struct DefineIndexStatement {
impl DefineIndexStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,7 +1,7 @@
use crate::ctx::Context;
use crate::dbs::Iterator;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::err::Error;
@ -31,7 +31,7 @@ pub struct DeleteStatement {
impl DeleteStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::shouldbespace;
@ -21,7 +21,7 @@ pub struct IfelseStatement {
impl IfelseStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,6 +1,6 @@
use crate::ctx::Context;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::shouldbespace;
@ -26,7 +26,7 @@ pub enum InfoStatement {
impl InfoStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,

View file

@ -1,7 +1,7 @@
use crate::ctx::Context;
use crate::dbs::Iterator;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::err::Error;
@ -34,7 +34,7 @@ pub struct InsertStatement {
impl InsertStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::shouldbespace;
@ -19,7 +19,7 @@ pub struct KillStatement {
impl KillStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
_doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::shouldbespace;
@ -27,7 +27,7 @@ pub struct LiveStatement {
impl LiveStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
_doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::shouldbespace;
@ -18,7 +18,7 @@ pub struct OutputStatement {
impl OutputStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,7 +1,7 @@
use crate::ctx::Context;
use crate::dbs::Iterator;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::err::Error;
@ -37,7 +37,7 @@ pub struct RelateStatement {
impl RelateStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,6 +1,6 @@
use crate::ctx::Context;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::base::{base, Base};
@ -32,7 +32,7 @@ pub enum RemoveStatement {
impl RemoveStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,
@ -93,7 +93,7 @@ pub struct RemoveNamespaceStatement {
impl RemoveNamespaceStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -147,7 +147,7 @@ pub struct RemoveDatabaseStatement {
impl RemoveDatabaseStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -202,7 +202,7 @@ pub struct RemoveLoginStatement {
impl RemoveLoginStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -277,7 +277,7 @@ pub struct RemoveTokenStatement {
impl RemoveTokenStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -351,7 +351,7 @@ pub struct RemoveScopeStatement {
impl RemoveScopeStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -402,7 +402,7 @@ pub struct RemoveTableStatement {
impl RemoveTableStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -457,7 +457,7 @@ pub struct RemoveEventStatement {
impl RemoveEventStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -515,7 +515,7 @@ pub struct RemoveFieldStatement {
impl RemoveFieldStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,
@ -573,7 +573,7 @@ pub struct RemoveIndexStatement {
impl RemoveIndexStatement {
pub(crate) async fn compute(
&self,
_ctx: &Runtime,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
_doc: Option<&Value>,

View file

@ -1,7 +1,7 @@
use crate::ctx::Context;
use crate::dbs::Iterator;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::err::Error;
@ -59,7 +59,7 @@ impl SelectStatement {
impl SelectStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::comment::mightbespace;
@ -23,7 +23,7 @@ pub struct SetStatement {
impl SetStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,7 +1,7 @@
use crate::ctx::Context;
use crate::dbs::Iterator;
use crate::dbs::Level;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Statement;
use crate::dbs::Transaction;
use crate::err::Error;
@ -32,7 +32,7 @@ pub struct UpdateStatement {
impl UpdateStatement {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,

View file

@ -1,6 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::error::IResult;
@ -41,7 +40,7 @@ impl PartialOrd for Subquery {
impl Subquery {
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&Value>,
@ -55,12 +54,9 @@ impl Subquery {
// Duplicate context
let mut ctx = Context::new(ctx);
// Add parent document
if doc.is_some() {
let doc = doc.unwrap().clone();
if let Some(doc) = doc {
ctx.add_value("parent".into(), doc);
}
// Prepare context
let ctx = ctx.freeze();
// Process subquery
let res = v.compute(&ctx, &opt, txn, doc).await?;
// Process result
@ -81,12 +77,9 @@ impl Subquery {
// Duplicate context
let mut ctx = Context::new(ctx);
// Add parent document
if doc.is_some() {
let doc = doc.unwrap().clone();
if let Some(doc) = doc {
ctx.add_value("parent".into(), doc);
}
// Prepare context
let ctx = ctx.freeze();
// Process subquery
match v.compute(&ctx, &opt, txn, doc).await? {
Value::Array(mut v) => match v.len() {
@ -102,12 +95,9 @@ impl Subquery {
// Duplicate context
let mut ctx = Context::new(ctx);
// Add parent document
if doc.is_some() {
let doc = doc.unwrap().clone();
if let Some(doc) = doc {
ctx.add_value("parent".into(), doc);
}
// Prepare context
let ctx = ctx.freeze();
// Process subquery
match v.compute(&ctx, &opt, txn, doc).await? {
Value::Array(mut v) => match v.len() {
@ -123,12 +113,9 @@ impl Subquery {
// Duplicate context
let mut ctx = Context::new(ctx);
// Add parent document
if doc.is_some() {
let doc = doc.unwrap().clone();
if let Some(doc) = doc {
ctx.add_value("parent".into(), doc);
}
// Prepare context
let ctx = ctx.freeze();
// Process subquery
match v.compute(&ctx, &opt, txn, doc).await? {
Value::Array(mut v) => match v.len() {
@ -144,12 +131,9 @@ impl Subquery {
// Duplicate context
let mut ctx = Context::new(ctx);
// Add parent document
if doc.is_some() {
let doc = doc.unwrap().clone();
if let Some(doc) = doc {
ctx.add_value("parent".into(), doc);
}
// Prepare context
let ctx = ctx.freeze();
// Process subquery
match v.compute(&ctx, &opt, txn, doc).await? {
Value::Array(mut v) => match v.len() {
@ -165,12 +149,9 @@ impl Subquery {
// Duplicate context
let mut ctx = Context::new(ctx);
// Add parent document
if doc.is_some() {
let doc = doc.unwrap().clone();
if let Some(doc) = doc {
ctx.add_value("parent".into(), doc);
}
// Prepare context
let ctx = ctx.freeze();
// Process subquery
match v.compute(&ctx, &opt, txn, doc).await? {
Value::Array(mut v) => match v.len() {

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::array::Array;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl Value {
pub async fn array(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
path: &[Part],

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::value::Value;
@ -7,7 +7,7 @@ use crate::sql::value::Value;
impl Value {
pub async fn clear(
&mut self,
_ctx: &Runtime,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
) -> Result<(), Error> {

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::number::Number;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl Value {
pub async fn decrement(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
path: &[Part],

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::part::Part;
@ -12,7 +12,7 @@ static RID: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("id")]);
impl Value {
pub async fn def(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
val: &Thing,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::array::Abolish;
@ -15,7 +15,7 @@ impl Value {
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
pub async fn del(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
path: &[Part],

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::field::{Field, Fields};
@ -16,7 +16,7 @@ impl Value {
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
pub async fn get(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
path: &[Part],

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::number::Number;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl Value {
pub async fn increment(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
path: &[Part],

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::part::Part;
@ -8,7 +8,7 @@ use crate::sql::value::Value;
impl Value {
pub async fn merge(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
val: &Value,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::object::Object;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl Value {
pub async fn object(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
path: &[Part],

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::array::Array;
@ -9,7 +9,7 @@ use crate::sql::value::Value;
impl Value {
pub async fn patch(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
val: &Array,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::value::Value;
@ -7,7 +7,7 @@ use crate::sql::value::Value;
impl Value {
pub async fn replace(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
val: &Value,

View file

@ -1,5 +1,5 @@
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::part::Next;
@ -13,7 +13,7 @@ impl Value {
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
pub async fn set(
&mut self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
path: &[Part],

View file

@ -1,7 +1,7 @@
#![allow(clippy::derive_ord_xor_partial_ord)]
use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Runtime;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::array::{array, Array};
@ -971,7 +971,7 @@ impl Value {
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
pub(crate) async fn compute(
&self,
ctx: &Runtime,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&'async_recursion Value>,