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:
parent
f414198fad
commit
1017e2fffb
84 changed files with 376 additions and 435 deletions
|
@ -1,32 +1,45 @@
|
||||||
use crate::ctx::canceller::Canceller;
|
use crate::ctx::canceller::Canceller;
|
||||||
use crate::ctx::reason::Reason;
|
use crate::ctx::reason::Reason;
|
||||||
use std::any::Any;
|
use crate::sql::value::Value;
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
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.
|
// An optional parent context.
|
||||||
parent: Option<Arc<Context>>,
|
parent: Option<&'a Context<'a>>,
|
||||||
// An optional deadline.
|
// An optional deadline.
|
||||||
deadline: Option<Instant>,
|
deadline: Option<Instant>,
|
||||||
// Wether or not this context is cancelled.
|
// Wether or not this context is cancelled.
|
||||||
cancelled: Arc<AtomicBool>,
|
cancelled: Arc<AtomicBool>,
|
||||||
// A collection of read only values stored in this context.
|
// 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 {
|
fn default() -> Self {
|
||||||
Context::background()
|
Context::background()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl<'a> Context<'a> {
|
||||||
// Create an empty background context.
|
// Create an empty background context.
|
||||||
pub fn background() -> Context {
|
pub fn background() -> Self {
|
||||||
Context {
|
Context {
|
||||||
values: None,
|
values: None,
|
||||||
parent: None,
|
parent: None,
|
||||||
|
@ -36,24 +49,15 @@ impl Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new child from a frozen context.
|
// Create a new child from a frozen context.
|
||||||
pub fn new(parent: &Arc<Context>) -> Context {
|
pub fn new(parent: &'a Context) -> Self {
|
||||||
Context {
|
Context {
|
||||||
values: None,
|
values: None,
|
||||||
parent: Some(Arc::clone(parent)),
|
parent: Some(parent),
|
||||||
deadline: parent.deadline,
|
deadline: parent.deadline,
|
||||||
cancelled: Arc::new(AtomicBool::new(false)),
|
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
|
// Add cancelation to the context. The value that is returned will cancel
|
||||||
// the context and it's children once called.
|
// the context and it's children once called.
|
||||||
pub fn add_cancel(&mut self) -> Canceller {
|
pub fn add_cancel(&mut self) -> Canceller {
|
||||||
|
@ -80,10 +84,10 @@ impl Context {
|
||||||
// with the same key.
|
// with the same key.
|
||||||
pub fn add_value<V>(&mut self, key: String, value: V)
|
pub fn add_value<V>(&mut self, key: String, value: V)
|
||||||
where
|
where
|
||||||
V: Any + Send + Sync + Sized,
|
V: Into<Cow<'a, Value>>,
|
||||||
{
|
{
|
||||||
if let Some(ref mut values) = self.values {
|
if let Some(ref mut values) = self.values {
|
||||||
values.insert(key, Box::new(value));
|
values.insert(key, value.into());
|
||||||
} else {
|
} else {
|
||||||
self.values = Some(HashMap::new());
|
self.values = Some(HashMap::new());
|
||||||
self.add_value(key, value);
|
self.add_value(key, value);
|
||||||
|
@ -104,7 +108,7 @@ impl Context {
|
||||||
// TODO: see if we can relax the ordering.
|
// TODO: see if we can relax the ordering.
|
||||||
_ if self.cancelled.load(Ordering::SeqCst) => Some(Reason::Canceled),
|
_ if self.cancelled.load(Ordering::SeqCst) => Some(Reason::Canceled),
|
||||||
_ => match self.parent {
|
_ => match self.parent {
|
||||||
Some(ref parent_ctx) => parent_ctx.done(),
|
Some(ctx) => ctx.done(),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -146,24 +150,27 @@ impl Context {
|
||||||
|
|
||||||
// Get a value from the context. If no value is stored under the
|
// Get a value from the context. If no value is stored under the
|
||||||
// provided key, then this will return None.
|
// provided key, then this will return None.
|
||||||
pub fn value<V>(&self, key: &str) -> Option<&V>
|
pub fn value(&self, key: &str) -> Option<&Value> {
|
||||||
where
|
match &self.values {
|
||||||
V: Any + Send + Sync + Sized,
|
Some(v) => match v.get(key) {
|
||||||
{
|
Some(v) => match v {
|
||||||
if let Some(ref values) = self.values {
|
Cow::Borrowed(v) => Some(*v),
|
||||||
if let Some(value) = values.get(key) {
|
Cow::Owned(v) => Some(v),
|
||||||
let value: &dyn Any = &**value;
|
},
|
||||||
return value.downcast_ref::<V>();
|
None => match self.parent {
|
||||||
}
|
Some(p) => p.value(key),
|
||||||
}
|
|
||||||
match self.parent {
|
|
||||||
Some(ref parent) => parent.value(key),
|
|
||||||
_ => None,
|
_ => 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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.debug_struct("Context")
|
f.debug_struct("Context")
|
||||||
.field("parent", &self.parent)
|
.field("parent", &self.parent)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
@ -16,7 +16,7 @@ use channel::Sender;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub(crate) async fn channel(
|
pub(crate) async fn channel(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -39,7 +39,7 @@ impl Array {
|
||||||
#[async_recursion]
|
#[async_recursion]
|
||||||
pub(crate) async fn process(
|
pub(crate) async fn process(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -63,7 +63,7 @@ impl Array {
|
||||||
impl Model {
|
impl Model {
|
||||||
pub(crate) async fn process(
|
pub(crate) async fn process(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -100,7 +100,7 @@ impl Model {
|
||||||
impl Thing {
|
impl Thing {
|
||||||
pub(crate) async fn process(
|
pub(crate) async fn process(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
@ -122,7 +122,7 @@ impl Thing {
|
||||||
impl Table {
|
impl Table {
|
||||||
pub(crate) async fn process(
|
pub(crate) async fn process(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::dbs::response::Response;
|
||||||
use crate::dbs::Auth;
|
use crate::dbs::Auth;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::kvs::Datastore;
|
use crate::kvs::Datastore;
|
||||||
|
@ -117,7 +116,7 @@ impl<'a> Executor<'a> {
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut ctx: Runtime,
|
mut ctx: Context<'_>,
|
||||||
mut opt: Options,
|
mut opt: Options,
|
||||||
qry: Query,
|
qry: Query,
|
||||||
) -> Result<Vec<Response>, Error> {
|
) -> Result<Vec<Response>, Error> {
|
||||||
|
@ -213,10 +212,7 @@ impl<'a> Executor<'a> {
|
||||||
// Process the statement
|
// Process the statement
|
||||||
match stm.compute(&ctx, &opt, &self.txn(), None).await {
|
match stm.compute(&ctx, &opt, &self.txn(), None).await {
|
||||||
Ok(val) => {
|
Ok(val) => {
|
||||||
let mut new = Context::new(&ctx);
|
ctx.add_value(stm.name.to_owned(), val);
|
||||||
let key = stm.name.to_owned();
|
|
||||||
new.add_value(key, val);
|
|
||||||
ctx = new.freeze();
|
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
|
@ -240,7 +236,6 @@ impl<'a> Executor<'a> {
|
||||||
// Set statement timeout
|
// Set statement timeout
|
||||||
let mut ctx = Context::new(&ctx);
|
let mut ctx = Context::new(&ctx);
|
||||||
ctx.add_timeout(timeout);
|
ctx.add_timeout(timeout);
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let res = stm.compute(&ctx, &opt, &self.txn(), None).await;
|
let res = stm.compute(&ctx, &opt, &self.txn(), None).await;
|
||||||
// Catch statement timeout
|
// Catch statement timeout
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Iterator;
|
use crate::dbs::Iterator;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
@ -18,7 +18,7 @@ impl Value {
|
||||||
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
||||||
pub(crate) async fn iterate(
|
pub(crate) async fn iterate(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -42,7 +42,7 @@ impl Array {
|
||||||
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
||||||
pub(crate) async fn iterate(
|
pub(crate) async fn iterate(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -66,7 +66,7 @@ impl Array {
|
||||||
impl Model {
|
impl Model {
|
||||||
pub(crate) async fn iterate(
|
pub(crate) async fn iterate(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -103,7 +103,7 @@ impl Model {
|
||||||
impl Thing {
|
impl Thing {
|
||||||
pub(crate) async fn iterate(
|
pub(crate) async fn iterate(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -125,7 +125,7 @@ impl Thing {
|
||||||
impl Table {
|
impl Table {
|
||||||
pub(crate) async fn iterate(
|
pub(crate) async fn iterate(
|
||||||
self,
|
self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -2,7 +2,6 @@ use crate::cnf::MAX_CONCURRENT_TASKS;
|
||||||
use crate::ctx::Canceller;
|
use crate::ctx::Canceller;
|
||||||
use crate::ctx::Context;
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -54,7 +53,7 @@ impl Iterator {
|
||||||
// Process the records and output
|
// Process the records and output
|
||||||
pub async fn output(
|
pub async fn output(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -64,7 +63,6 @@ impl Iterator {
|
||||||
// Enable context override
|
// Enable context override
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
self.run = ctx.add_cancel();
|
self.run = ctx.add_cancel();
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process prepared values
|
// Process prepared values
|
||||||
self.iterate(&ctx, opt, txn, stm).await?;
|
self.iterate(&ctx, opt, txn, stm).await?;
|
||||||
// Return any document errors
|
// Return any document errors
|
||||||
|
@ -90,7 +88,7 @@ impl Iterator {
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn output_split(
|
async fn output_split(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -134,7 +132,7 @@ impl Iterator {
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn output_group(
|
async fn output_group(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -217,7 +215,7 @@ impl Iterator {
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn output_order(
|
async fn output_order(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -256,7 +254,7 @@ impl Iterator {
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn output_start(
|
async fn output_start(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -270,7 +268,7 @@ impl Iterator {
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn output_limit(
|
async fn output_limit(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -284,7 +282,7 @@ impl Iterator {
|
||||||
#[inline]
|
#[inline]
|
||||||
async fn output_fetch(
|
async fn output_fetch(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -323,7 +321,7 @@ impl Iterator {
|
||||||
#[cfg(not(feature = "parallel"))]
|
#[cfg(not(feature = "parallel"))]
|
||||||
async fn iterate(
|
async fn iterate(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -339,7 +337,7 @@ impl Iterator {
|
||||||
#[cfg(feature = "parallel")]
|
#[cfg(feature = "parallel")]
|
||||||
async fn iterate(
|
async fn iterate(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -412,7 +410,7 @@ impl Iterator {
|
||||||
// Process a new record Thing and Value
|
// Process a new record Thing and Value
|
||||||
pub async fn process(
|
pub async fn process(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -4,7 +4,6 @@ mod iterate;
|
||||||
mod iterator;
|
mod iterator;
|
||||||
mod options;
|
mod options;
|
||||||
mod response;
|
mod response;
|
||||||
mod runtime;
|
|
||||||
mod session;
|
mod session;
|
||||||
mod statement;
|
mod statement;
|
||||||
mod transaction;
|
mod transaction;
|
||||||
|
@ -15,7 +14,6 @@ pub use self::executor::*;
|
||||||
pub use self::iterator::*;
|
pub use self::iterator::*;
|
||||||
pub use self::options::*;
|
pub use self::options::*;
|
||||||
pub use self::response::*;
|
pub use self::response::*;
|
||||||
pub use self::runtime::*;
|
|
||||||
pub use self::session::*;
|
pub use self::session::*;
|
||||||
pub use self::statement::*;
|
pub use self::statement::*;
|
||||||
pub use self::transaction::*;
|
pub use self::transaction::*;
|
||||||
|
|
|
@ -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>;
|
|
|
@ -34,7 +34,7 @@ impl Session {
|
||||||
self.db.to_owned().map(Arc::new)
|
self.db.to_owned().map(Arc::new)
|
||||||
}
|
}
|
||||||
// Convert a session into a runtime
|
// 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
|
// Add session value
|
||||||
let key = String::from("session");
|
let key = String::from("session");
|
||||||
let val: Value = self.into();
|
let val: Value = self.into();
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
use crate::ctx::Context;
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::kvs::Datastore;
|
use crate::kvs::Datastore;
|
||||||
use futures::lock::Mutex;
|
use futures::lock::Mutex;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub async fn mock<'a>() -> (Runtime, Options, Transaction) {
|
pub async fn mock<'a>() -> (Context<'a>, Options, Transaction) {
|
||||||
let ctx = Context::default().freeze();
|
let ctx = Context::default();
|
||||||
let opt = Options::default();
|
let opt = Options::default();
|
||||||
let kvs = Datastore::new("memory").await.unwrap();
|
let kvs = Datastore::new("memory").await.unwrap();
|
||||||
let txn = kvs.transaction(true, false).await.unwrap();
|
let txn = kvs.transaction(true, false).await.unwrap();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn admit(
|
pub async fn admit(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::permission::Permission;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn allow(
|
pub async fn allow(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn check(
|
pub async fn check(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -10,7 +10,7 @@ use channel::Sender;
|
||||||
|
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn delete(
|
pub async fn delete(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn empty(
|
pub async fn empty(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn erase(
|
pub async fn erase(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::ctx::Context;
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -11,7 +10,7 @@ use std::ops::Deref;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn event(
|
pub async fn event(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
@ -37,10 +36,9 @@ impl<'a> Document<'a> {
|
||||||
// Configure the context
|
// Configure the context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
ctx.add_value("event".into(), met);
|
ctx.add_value("event".into(), met);
|
||||||
ctx.add_value("value".into(), self.current.deref().clone());
|
ctx.add_value("value".into(), self.current.deref());
|
||||||
ctx.add_value("after".into(), self.current.deref().clone());
|
ctx.add_value("after".into(), self.current.deref());
|
||||||
ctx.add_value("before".into(), self.initial.deref().clone());
|
ctx.add_value("before".into(), self.initial.deref());
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Ensure event queries run
|
// Ensure event queries run
|
||||||
let opt = &opt.perms(false);
|
let opt = &opt.perms(false);
|
||||||
// Process conditional clause
|
// Process conditional clause
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn exist(
|
pub async fn exist(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::ctx::Context;
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -11,7 +10,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn field(
|
pub async fn field(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
@ -28,10 +27,9 @@ impl<'a> Document<'a> {
|
||||||
if let Some(expr) = &fd.value {
|
if let Some(expr) = &fd.value {
|
||||||
// Configure the context
|
// Configure the context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
ctx.add_value("value".into(), val.clone());
|
ctx.add_value("value".into(), &val);
|
||||||
ctx.add_value("after".into(), val.clone());
|
ctx.add_value("after".into(), &val);
|
||||||
ctx.add_value("before".into(), old.clone());
|
ctx.add_value("before".into(), &old);
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process the VALUE clause
|
// Process the VALUE clause
|
||||||
val = expr.compute(&ctx, opt, txn, Some(&self.current)).await?;
|
val = expr.compute(&ctx, opt, txn, Some(&self.current)).await?;
|
||||||
}
|
}
|
||||||
|
@ -43,10 +41,9 @@ impl<'a> Document<'a> {
|
||||||
if let Some(expr) = &fd.assert {
|
if let Some(expr) = &fd.assert {
|
||||||
// Configure the context
|
// Configure the context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
ctx.add_value("value".into(), val.clone());
|
ctx.add_value("value".into(), &val);
|
||||||
ctx.add_value("after".into(), val.clone());
|
ctx.add_value("after".into(), &val);
|
||||||
ctx.add_value("before".into(), old.clone());
|
ctx.add_value("before".into(), &old);
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process the ASSERT clause
|
// Process the ASSERT clause
|
||||||
if !expr.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
if !expr.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
||||||
return Err(Error::FieldValue {
|
return Err(Error::FieldValue {
|
||||||
|
@ -73,10 +70,9 @@ impl<'a> Document<'a> {
|
||||||
Permission::Specific(e) => {
|
Permission::Specific(e) => {
|
||||||
// Configure the context
|
// Configure the context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
ctx.add_value("value".into(), val.clone());
|
ctx.add_value("value".into(), &val);
|
||||||
ctx.add_value("after".into(), val.clone());
|
ctx.add_value("after".into(), &val);
|
||||||
ctx.add_value("before".into(), old.clone());
|
ctx.add_value("before".into(), &old);
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process the PERMISSION clause
|
// Process the PERMISSION clause
|
||||||
if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
||||||
val = old
|
val = old
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::array::Array;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn index(
|
pub async fn index(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn lives(
|
pub async fn lives(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -11,7 +11,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn merge(
|
pub async fn merge(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::ctx::Context;
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -14,7 +13,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn pluck(
|
pub async fn pluck(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
@ -127,8 +126,7 @@ impl<'a> Document<'a> {
|
||||||
let val = self.current.pick(k);
|
let val = self.current.pick(k);
|
||||||
// Configure the context
|
// Configure the context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
ctx.add_value("value".into(), val);
|
ctx.add_value("value".into(), &val);
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process the PERMISSION clause
|
// Process the PERMISSION clause
|
||||||
if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
if !e.compute(&ctx, opt, txn, Some(&self.current)).await?.is_truthy() {
|
||||||
out.del(&ctx, opt, txn, k).await?
|
out.del(&ctx, opt, txn, k).await?
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn purge(
|
pub async fn purge(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn relate(
|
pub async fn relate(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn select(
|
pub async fn select(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn store(
|
pub async fn store(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -8,7 +8,7 @@ use crate::err::Error;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn table(
|
pub async fn table(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
_stm: &Statement<'_>,
|
_stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@ pub enum Args {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(
|
pub fn check(
|
||||||
ctx: &Runtime,
|
ctx: &Context,
|
||||||
name: &str,
|
name: &str,
|
||||||
args: Vec<Value>,
|
args: Vec<Value>,
|
||||||
size: Args,
|
size: Args,
|
||||||
func: fn(&Runtime, Vec<Value>) -> Result<Value, Error>,
|
func: fn(&Context, Vec<Value>) -> Result<Value, Error>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
match size {
|
match size {
|
||||||
Args::None => match args.len() {
|
Args::None => match args.len() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::array::Combine;
|
use crate::sql::array::Combine;
|
||||||
use crate::sql::array::Concat;
|
use crate::sql::array::Concat;
|
||||||
|
@ -8,7 +8,7 @@ use crate::sql::array::Union;
|
||||||
use crate::sql::array::Uniq;
|
use crate::sql::array::Uniq;
|
||||||
use crate::sql::value::Value;
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => match args.remove(0) {
|
Value::Array(v) => match args.remove(0) {
|
||||||
Value::Array(w) => Ok(v.concat(w).into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => match args.remove(0) {
|
Value::Array(v) => match args.remove(0) {
|
||||||
Value::Array(w) => Ok(v.combine(w).into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => match args.remove(0) {
|
Value::Array(v) => match args.remove(0) {
|
||||||
Value::Array(w) => Ok(v.difference(w).into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.uniq().into()),
|
Value::Array(v) => Ok(v.uniq().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => match args.remove(0) {
|
Value::Array(v) => match args.remove(0) {
|
||||||
Value::Array(w) => Ok(v.intersect(w).into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.len().into()),
|
Value::Array(v) => Ok(v.len().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => match args.remove(0) {
|
Value::Array(v) => match args.remove(0) {
|
||||||
Value::Array(w) => Ok(v.union(w).into()),
|
Value::Array(w) => Ok(v.union(w).into()),
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::number::Number;
|
use crate::sql::number::Number;
|
||||||
use crate::sql::value::Value;
|
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 {
|
match name {
|
||||||
"bool" => bool(ctx, val),
|
"bool" => bool(ctx, val),
|
||||||
"int" => int(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() {
|
match val.is_truthy() {
|
||||||
true => Ok(Value::True),
|
true => Ok(Value::True),
|
||||||
false => Ok(Value::False),
|
false => Ok(Value::False),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int(_: &Runtime, val: Value) -> Result<Value, Error> {
|
pub fn int(_: &Context, val: Value) -> Result<Value, Error> {
|
||||||
match val {
|
match val {
|
||||||
Value::Number(Number::Int(_)) => Ok(val),
|
Value::Number(Number::Int(_)) => Ok(val),
|
||||||
_ => Ok(Value::Number(Number::Int(val.as_int()))),
|
_ => 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 {
|
match val {
|
||||||
Value::Number(Number::Float(_)) => Ok(val),
|
Value::Number(Number::Float(_)) => Ok(val),
|
||||||
_ => Ok(Value::Number(Number::Float(val.as_float()))),
|
_ => 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 {
|
match val {
|
||||||
Value::Number(Number::Decimal(_)) => Ok(val),
|
Value::Number(Number::Decimal(_)) => Ok(val),
|
||||||
_ => Ok(Value::Number(Number::Decimal(val.as_decimal()))),
|
_ => 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 {
|
match val {
|
||||||
Value::Number(Number::Decimal(_)) => Ok(val),
|
Value::Number(Number::Decimal(_)) => Ok(val),
|
||||||
_ => Ok(Value::Number(Number::Decimal(val.as_decimal()))),
|
_ => 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 {
|
match val {
|
||||||
Value::Strand(_) => Ok(val),
|
Value::Strand(_) => Ok(val),
|
||||||
_ => Ok(Value::Strand(val.as_strand())),
|
_ => 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 {
|
match val {
|
||||||
Value::Datetime(_) => Ok(val),
|
Value::Datetime(_) => Ok(val),
|
||||||
_ => Ok(Value::Datetime(val.as_datetime())),
|
_ => 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 {
|
match val {
|
||||||
Value::Duration(_) => Ok(val),
|
Value::Duration(_) => Ok(val),
|
||||||
_ => Ok(Value::Duration(val.as_duration())),
|
_ => Ok(Value::Duration(val.as_duration())),
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
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() {
|
match args.len() {
|
||||||
1 => match args.remove(0) {
|
1 => match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.iter().filter(|v| v.is_truthy()).count().into()),
|
Value::Array(v) => Ok(v.iter().filter(|v| v.is_truthy()).count().into()),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use md5::Digest;
|
use md5::Digest;
|
||||||
|
@ -7,7 +7,7 @@ use sha1::Sha1;
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
use sha2::Sha512;
|
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();
|
let mut hasher = Md5::new();
|
||||||
hasher.update(args.remove(0).as_string().as_str());
|
hasher.update(args.remove(0).as_string().as_str());
|
||||||
let val = hasher.finalize();
|
let val = hasher.finalize();
|
||||||
|
@ -15,7 +15,7 @@ pub fn md5(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||||
Ok(val.into())
|
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();
|
let mut hasher = Sha1::new();
|
||||||
hasher.update(args.remove(0).as_string().as_str());
|
hasher.update(args.remove(0).as_string().as_str());
|
||||||
let val = hasher.finalize();
|
let val = hasher.finalize();
|
||||||
|
@ -23,7 +23,7 @@ pub fn sha1(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||||
Ok(val.into())
|
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();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(args.remove(0).as_string().as_str());
|
hasher.update(args.remove(0).as_string().as_str());
|
||||||
let val = hasher.finalize();
|
let val = hasher.finalize();
|
||||||
|
@ -31,7 +31,7 @@ pub fn sha256(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||||
Ok(val.into())
|
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();
|
let mut hasher = Sha512::new();
|
||||||
hasher.update(args.remove(0).as_string().as_str());
|
hasher.update(args.remove(0).as_string().as_str());
|
||||||
let val = hasher.finalize();
|
let val = hasher.finalize();
|
||||||
|
@ -41,7 +41,7 @@ pub fn sha512(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||||
|
|
||||||
pub mod argon2 {
|
pub mod argon2 {
|
||||||
|
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use argon2::{
|
use argon2::{
|
||||||
|
@ -50,7 +50,7 @@ pub mod argon2 {
|
||||||
};
|
};
|
||||||
use rand::rngs::OsRng;
|
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 algo = Argon2::default();
|
||||||
let hash = args.remove(0).as_string();
|
let hash = args.remove(0).as_string();
|
||||||
let pass = 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())
|
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 algo = Argon2::default();
|
||||||
let pass = args.remove(0).as_string();
|
let pass = args.remove(0).as_string();
|
||||||
let salt = SaltString::generate(&mut OsRng);
|
let salt = SaltString::generate(&mut OsRng);
|
||||||
|
@ -69,7 +69,7 @@ pub mod argon2 {
|
||||||
|
|
||||||
pub mod pbkdf2 {
|
pub mod pbkdf2 {
|
||||||
|
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use pbkdf2::{
|
use pbkdf2::{
|
||||||
|
@ -78,14 +78,14 @@ pub mod pbkdf2 {
|
||||||
};
|
};
|
||||||
use rand::rngs::OsRng;
|
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 hash = args.remove(0).as_string();
|
||||||
let pass = args.remove(0).as_string();
|
let pass = args.remove(0).as_string();
|
||||||
let test = PasswordHash::new(&hash).unwrap();
|
let test = PasswordHash::new(&hash).unwrap();
|
||||||
Ok(Pbkdf2.verify_password(pass.as_ref(), &test).is_ok().into())
|
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 pass = args.remove(0).as_string();
|
||||||
let salt = SaltString::generate(&mut OsRng);
|
let salt = SaltString::generate(&mut OsRng);
|
||||||
let hash = Pbkdf2.hash_password(pass.as_ref(), salt.as_ref()).unwrap().to_string();
|
let hash = Pbkdf2.hash_password(pass.as_ref(), salt.as_ref()).unwrap().to_string();
|
||||||
|
@ -95,7 +95,7 @@ pub mod pbkdf2 {
|
||||||
|
|
||||||
pub mod scrypt {
|
pub mod scrypt {
|
||||||
|
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
|
@ -104,14 +104,14 @@ pub mod scrypt {
|
||||||
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 hash = args.remove(0).as_string();
|
||||||
let pass = args.remove(0).as_string();
|
let pass = args.remove(0).as_string();
|
||||||
let test = PasswordHash::new(&hash).unwrap();
|
let test = PasswordHash::new(&hash).unwrap();
|
||||||
Ok(Scrypt.verify_password(pass.as_ref(), &test).is_ok().into())
|
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 pass = args.remove(0).as_string();
|
||||||
let salt = SaltString::generate(&mut OsRng);
|
let salt = SaltString::generate(&mut OsRng);
|
||||||
let hash = Scrypt.hash_password(pass.as_ref(), salt.as_ref()).unwrap().to_string();
|
let hash = Scrypt.hash_password(pass.as_ref(), salt.as_ref()).unwrap().to_string();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
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)
|
Ok(expr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::geometry::Geometry;
|
use crate::sql::geometry::Geometry;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
@ -7,7 +7,7 @@ use geo::algorithm::bearing::Bearing;
|
||||||
use geo::algorithm::centroid::Centroid;
|
use geo::algorithm::centroid::Centroid;
|
||||||
use geo::algorithm::haversine_distance::HaversineDistance;
|
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) {
|
match args.remove(0) {
|
||||||
Value::Geometry(v) => match v {
|
Value::Geometry(v) => match v {
|
||||||
Geometry::Point(v) => Ok(v.signed_area().into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Geometry(Geometry::Point(v)) => match args.remove(0) {
|
Value::Geometry(Geometry::Point(v)) => match args.remove(0) {
|
||||||
Value::Geometry(Geometry::Point(w)) => Ok(v.bearing(w).into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Geometry(v) => match v {
|
Value::Geometry(v) => match v {
|
||||||
Geometry::Point(v) => Ok(v.centroid().into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Geometry(Geometry::Point(v)) => match args.remove(0) {
|
Value::Geometry(Geometry::Point(v)) => match args.remove(0) {
|
||||||
Value::Geometry(Geometry::Point(w)) => Ok(v.haversine_distance(&w).into()),
|
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 {
|
pub mod hash {
|
||||||
|
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::fnc::util::geo;
|
use crate::fnc::util::geo;
|
||||||
use crate::sql::geometry::Geometry;
|
use crate::sql::geometry::Geometry;
|
||||||
use crate::sql::value::Value;
|
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() {
|
match args.len() {
|
||||||
2 => match args.remove(0) {
|
2 => match args.remove(0) {
|
||||||
Value::Geometry(Geometry::Point(v)) => match args.remove(0).as_int() {
|
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) {
|
match args.remove(0) {
|
||||||
Value::Strand(v) => Ok(geo::decode(v).into()),
|
Value::Strand(v) => Ok(geo::decode(v).into()),
|
||||||
_ => Ok(Value::None),
|
_ => Ok(Value::None),
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
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() {
|
match args.len() {
|
||||||
1 | 2 => todo!(),
|
1 | 2 => todo!(),
|
||||||
_ => Err(Error::InvalidArguments {
|
_ => 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() {
|
match args.len() {
|
||||||
1 | 2 => todo!(),
|
1 | 2 => todo!(),
|
||||||
_ => Err(Error::InvalidArguments {
|
_ => 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() {
|
match args.len() {
|
||||||
1 | 2 | 3 => todo!(),
|
1 | 2 | 3 => todo!(),
|
||||||
_ => Err(Error::InvalidArguments {
|
_ => 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() {
|
match args.len() {
|
||||||
1 | 2 | 3 => todo!(),
|
1 | 2 | 3 => todo!(),
|
||||||
_ => Err(Error::InvalidArguments {
|
_ => 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() {
|
match args.len() {
|
||||||
1 | 2 | 3 => todo!(),
|
1 | 2 | 3 => todo!(),
|
||||||
_ => Err(Error::InvalidArguments {
|
_ => 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() {
|
match args.len() {
|
||||||
1 | 2 => todo!(),
|
1 | 2 => todo!(),
|
||||||
_ => Err(Error::InvalidArguments {
|
_ => Err(Error::InvalidArguments {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use once_cell::sync::Lazy;
|
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 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());
|
#[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())
|
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())
|
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())
|
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())
|
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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Convert to a &str
|
// Convert to a &str
|
||||||
|
@ -56,26 +56,26 @@ pub fn email(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||||
Ok(Value::True)
|
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())
|
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())
|
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())
|
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())
|
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())
|
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())
|
Ok(UUID_RE.is_match(args.remove(0).as_string().as_str()).into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::fnc::util::math::bottom::Bottom;
|
use crate::fnc::util::math::bottom::Bottom;
|
||||||
use crate::fnc::util::math::deviation::Deviation;
|
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::number::Number;
|
||||||
use crate::sql::value::Value;
|
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())
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => {
|
Value::Array(v) => {
|
||||||
let c = args.remove(0).as_int();
|
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())
|
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);
|
let v = args.remove(0);
|
||||||
match args.remove(0).as_int() {
|
match args.remove(0).as_int() {
|
||||||
p if p > 0 => Ok(v.as_number().fixed(p as usize).into()),
|
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())
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().interquartile().into()),
|
Value::Array(v) => Ok(v.as_numbers().interquartile().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => match v.as_numbers().into_iter().max() {
|
Value::Array(v) => match v.as_numbers().into_iter().max() {
|
||||||
Some(v) => Ok(v.into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().mean().into()),
|
Value::Array(v) => Ok(v.as_numbers().mean().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().median().into()),
|
Value::Array(v) => Ok(v.as_numbers().median().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().midhinge().into()),
|
Value::Array(v) => Ok(v.as_numbers().midhinge().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => match v.as_numbers().into_iter().min() {
|
Value::Array(v) => match v.as_numbers().into_iter().min() {
|
||||||
Some(v) => Ok(v.into()),
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().mode().into()),
|
Value::Array(v) => Ok(v.as_numbers().mode().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().nearestrank(args.remove(0).as_number()).into()),
|
Value::Array(v) => Ok(v.as_numbers().nearestrank(args.remove(0).as_number()).into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().percentile(args.remove(0).as_number()).into()),
|
Value::Array(v) => Ok(v.as_numbers().percentile(args.remove(0).as_number()).into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().into_iter().product::<Number>().into()),
|
Value::Array(v) => Ok(v.as_numbers().into_iter().product::<Number>().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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())
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().spread().into()),
|
Value::Array(v) => Ok(v.as_numbers().spread().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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())
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().deviation().into()),
|
Value::Array(v) => Ok(v.as_numbers().deviation().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().into_iter().sum::<Number>().into()),
|
Value::Array(v) => Ok(v.as_numbers().into_iter().sum::<Number>().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => {
|
Value::Array(v) => {
|
||||||
let c = args.remove(0).as_int();
|
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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().trimean().into()),
|
Value::Array(v) => Ok(v.as_numbers().trimean().into()),
|
||||||
_ => Ok(Value::None),
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Array(v) => Ok(v.as_numbers().variance().into()),
|
Value::Array(v) => Ok(v.as_numbers().variance().into()),
|
||||||
_ => Ok(Value::None),
|
_ => Ok(Value::None),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::fnc::args::Args;
|
use crate::fnc::args::Args;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
@ -22,7 +22,7 @@ pub mod time;
|
||||||
pub mod r#type;
|
pub mod r#type;
|
||||||
pub mod util;
|
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 {
|
match name {
|
||||||
//
|
//
|
||||||
"array::combine" => args::check(ctx, name, args, Args::Two, array::combine),
|
"array::combine" => args::check(ctx, name, args, Args::Two, array::combine),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
pub mod email {
|
pub mod email {
|
||||||
|
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use once_cell::sync::Lazy;
|
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 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());
|
#[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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Check if value is empty
|
// Check if value is empty
|
||||||
|
@ -34,7 +34,7 @@ pub mod email {
|
||||||
Ok(parts[0].into())
|
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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Check if value is empty
|
// Check if value is empty
|
||||||
|
@ -62,12 +62,12 @@ pub mod email {
|
||||||
|
|
||||||
pub mod url {
|
pub mod url {
|
||||||
|
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use url::Url;
|
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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Parse the URL
|
// 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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Parse the URL
|
// 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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Parse the URL
|
// 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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Parse the URL
|
// 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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Parse the URL
|
// 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
|
// Convert to a String
|
||||||
let val = args.remove(0).as_string();
|
let val = args.remove(0).as_string();
|
||||||
// Parse the URL
|
// Parse the URL
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::cnf::ID_CHARS;
|
use crate::cnf::ID_CHARS;
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::datetime::Datetime;
|
use crate::sql::datetime::Datetime;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
@ -8,15 +8,15 @@ use rand::distributions::Alphanumeric;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use uuid::Uuid;
|
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())
|
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())
|
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() {
|
match args.len() {
|
||||||
0 => Ok(Value::None),
|
0 => Ok(Value::None),
|
||||||
1 => match args.remove(0) {
|
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() {
|
match args.len() {
|
||||||
2 => {
|
2 => {
|
||||||
let min = args.remove(0).as_float();
|
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() {
|
match args.len() {
|
||||||
1 => {
|
1 => {
|
||||||
let len = args.remove(0).as_int() as usize;
|
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() {
|
match args.len() {
|
||||||
2 => {
|
2 => {
|
||||||
let min = args.remove(0).as_int();
|
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() {
|
match args.len() {
|
||||||
2 => match args.remove(0).as_int() {
|
2 => match args.remove(0).as_int() {
|
||||||
min if min >= 0 => 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() {
|
match args.len() {
|
||||||
2 => {
|
2 => {
|
||||||
let min = args.remove(0).as_int();
|
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())
|
Ok(Uuid::new_v4().to_string().into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::script::Script;
|
use crate::sql::script::Script;
|
||||||
use crate::sql::value::Value;
|
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 {
|
Err(Error::InvalidScript {
|
||||||
message: String::from("Embedded functions are not yet supported."),
|
message: String::from("Embedded functions are not yet supported."),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,53 +1,53 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
use slug::slugify;
|
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())
|
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 val = args.remove(0).as_string();
|
||||||
let chr = args.remove(0).as_string();
|
let chr = args.remove(0).as_string();
|
||||||
Ok(val.ends_with(&chr).into())
|
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 chr = args.remove(0).as_string();
|
||||||
let val = args.into_iter().map(|x| x.as_string());
|
let val = args.into_iter().map(|x| x.as_string());
|
||||||
let val = val.collect::<Vec<_>>().join(&chr);
|
let val = val.collect::<Vec<_>>().join(&chr);
|
||||||
Ok(val.into())
|
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 val = args.remove(0).as_string();
|
||||||
let num = val.chars().count() as i64;
|
let num = val.chars().count() as i64;
|
||||||
Ok(num.into())
|
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())
|
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 val = args.remove(0).as_string();
|
||||||
let num = args.remove(0).as_int() as usize;
|
let num = args.remove(0).as_int() as usize;
|
||||||
Ok(val.repeat(num).into())
|
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 val = args.remove(0).as_string();
|
||||||
let old = args.remove(0).as_string();
|
let old = args.remove(0).as_string();
|
||||||
let new = args.remove(0).as_string();
|
let new = args.remove(0).as_string();
|
||||||
Ok(val.replace(&old, &new).into())
|
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())
|
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 val = args.remove(0).as_string();
|
||||||
let beg = args.remove(0).as_int() as usize;
|
let beg = args.remove(0).as_int() as usize;
|
||||||
let lim = 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())
|
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())
|
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 val = args.remove(0).as_string();
|
||||||
let chr = args.remove(0).as_string();
|
let chr = args.remove(0).as_string();
|
||||||
let val = val.split(&chr).collect::<Vec<&str>>();
|
let val = val.split(&chr).collect::<Vec<&str>>();
|
||||||
Ok(val.into())
|
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 val = args.remove(0).as_string();
|
||||||
let chr = args.remove(0).as_string();
|
let chr = args.remove(0).as_string();
|
||||||
Ok(val.starts_with(&chr).into())
|
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())
|
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())
|
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())
|
Ok(args.remove(0).as_string().split(' ').collect::<Vec<&str>>().into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::datetime::Datetime;
|
use crate::sql::datetime::Datetime;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
@ -8,7 +8,7 @@ use chrono::DurationRound;
|
||||||
use chrono::Timelike;
|
use chrono::Timelike;
|
||||||
use chrono::Utc;
|
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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().day().into()),
|
0 => Ok(Utc::now().day().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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) {
|
match args.remove(0) {
|
||||||
Value::Datetime(v) => match args.remove(0) {
|
Value::Datetime(v) => match args.remove(0) {
|
||||||
Value::Duration(w) => match chrono::Duration::from_std(*w) {
|
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) {
|
match args.remove(0) {
|
||||||
Value::Datetime(v) => match args.remove(0) {
|
Value::Datetime(v) => match args.remove(0) {
|
||||||
Value::Strand(g) => match g.as_str() {
|
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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().hour().into()),
|
0 => Ok(Utc::now().hour().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().minute().into()),
|
0 => Ok(Utc::now().minute().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().day().into()),
|
0 => Ok(Utc::now().day().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().timestamp_nanos().into()),
|
0 => Ok(Utc::now().timestamp_nanos().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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())
|
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) {
|
match args.remove(0) {
|
||||||
Value::Datetime(v) => match args.remove(0) {
|
Value::Datetime(v) => match args.remove(0) {
|
||||||
Value::Duration(w) => match chrono::Duration::from_std(*w) {
|
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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().second().into()),
|
0 => Ok(Utc::now().second().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().timestamp().into()),
|
0 => Ok(Utc::now().timestamp().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().weekday().number_from_monday().into()),
|
0 => Ok(Utc::now().weekday().number_from_monday().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().iso_week().week().into()),
|
0 => Ok(Utc::now().iso_week().week().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().ordinal().into()),
|
0 => Ok(Utc::now().ordinal().into()),
|
||||||
_ => match args.remove(0) {
|
_ => 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() {
|
match args.len() {
|
||||||
0 => Ok(Utc::now().year().into()),
|
0 => Ok(Utc::now().year().into()),
|
||||||
_ => match args.remove(0) {
|
_ => match args.remove(0) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::Runtime;
|
use crate::ctx::Context;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::geometry::Geometry;
|
use crate::sql::geometry::Geometry;
|
||||||
use crate::sql::number::Number;
|
use crate::sql::number::Number;
|
||||||
|
@ -6,14 +6,14 @@ use crate::sql::table::Table;
|
||||||
use crate::sql::thing::Thing;
|
use crate::sql::thing::Thing;
|
||||||
use crate::sql::value::Value;
|
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() {
|
match args.remove(0).is_truthy() {
|
||||||
true => Ok(Value::True),
|
true => Ok(Value::True),
|
||||||
false => Ok(Value::False),
|
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);
|
let val = args.remove(0);
|
||||||
match val {
|
match val {
|
||||||
Value::Datetime(_) => Ok(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);
|
let val = args.remove(0);
|
||||||
match val {
|
match val {
|
||||||
Value::Number(Number::Decimal(_)) => Ok(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);
|
let val = args.remove(0);
|
||||||
match val {
|
match val {
|
||||||
Value::Duration(_) => Ok(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);
|
let val = args.remove(0);
|
||||||
match val {
|
match val {
|
||||||
Value::Number(Number::Float(_)) => Ok(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);
|
let val = args.remove(0);
|
||||||
match val {
|
match val {
|
||||||
Value::Number(Number::Int(_)) => Ok(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);
|
let val = args.remove(0);
|
||||||
match val {
|
match val {
|
||||||
Value::Number(_) => Ok(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() {
|
match args.len() {
|
||||||
2 => {
|
2 => {
|
||||||
let x = args.remove(0);
|
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) {
|
match args.remove(0) {
|
||||||
Value::Strand(v) => Ok(Value::Regex(v.as_str().into())),
|
Value::Strand(v) => Ok(Value::Regex(v.as_str().into())),
|
||||||
_ => Ok(Value::None),
|
_ => 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);
|
let val = args.remove(0);
|
||||||
match val {
|
match val {
|
||||||
Value::Strand(_) => Ok(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())))
|
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);
|
let tb = args.remove(0);
|
||||||
match args.remove(0) {
|
match args.remove(0) {
|
||||||
Value::Thing(id) => Ok(Value::Thing(Thing {
|
Value::Thing(id) => Ok(Value::Thing(Thing {
|
||||||
|
|
|
@ -163,8 +163,6 @@ impl Datastore {
|
||||||
let ctx = vars.attach(ctx);
|
let ctx = vars.attach(ctx);
|
||||||
// Parse the SQL query text
|
// Parse the SQL query text
|
||||||
let ast = sql::parse(txt)?;
|
let ast = sql::parse(txt)?;
|
||||||
// Freeze the context
|
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process all statements
|
// Process all statements
|
||||||
opt.auth = sess.au.clone();
|
opt.auth = sess.au.clone();
|
||||||
opt.ns = sess.ns();
|
opt.ns = sess.ns();
|
||||||
|
@ -189,8 +187,6 @@ impl Datastore {
|
||||||
let ctx = sess.context(ctx);
|
let ctx = sess.context(ctx);
|
||||||
// Store the query variables
|
// Store the query variables
|
||||||
let ctx = vars.attach(ctx);
|
let ctx = vars.attach(ctx);
|
||||||
// Freeze the context
|
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process all statements
|
// Process all statements
|
||||||
opt.auth = sess.au.clone();
|
opt.auth = sess.au.clone();
|
||||||
opt.ns = sess.ns();
|
opt.ns = sess.ns();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::mightbespace;
|
use crate::sql::comment::mightbespace;
|
||||||
|
@ -132,7 +132,7 @@ impl Array {
|
||||||
impl Array {
|
impl Array {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::fnc;
|
use crate::fnc;
|
||||||
|
@ -59,7 +59,7 @@ impl Expression {
|
||||||
impl Expression {
|
impl Expression {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::fnc;
|
use crate::fnc;
|
||||||
|
@ -104,7 +104,7 @@ impl Function {
|
||||||
impl Function {
|
impl Function {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::common::commas;
|
use crate::sql::common::commas;
|
||||||
|
@ -72,7 +72,7 @@ impl Idiom {
|
||||||
impl Idiom {
|
impl Idiom {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::mightbespace;
|
use crate::sql::comment::mightbespace;
|
||||||
|
@ -100,7 +100,7 @@ impl Object {
|
||||||
impl Object {
|
impl Object {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::error::IResult;
|
use crate::sql::error::IResult;
|
||||||
|
@ -33,7 +33,7 @@ impl Deref for Param {
|
||||||
impl Param {
|
impl Param {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
@ -55,7 +55,7 @@ impl Param {
|
||||||
// The base document does not exist
|
// The base document does not exist
|
||||||
None => Ok(Value::None),
|
None => Ok(Value::None),
|
||||||
},
|
},
|
||||||
_ => match ctx.value::<Value>(v) {
|
_ => match ctx.value(v) {
|
||||||
// The base variable exists
|
// The base variable exists
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
// Get the path parts
|
// Get the path parts
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::{comment, mightbespace};
|
use crate::sql::comment::{comment, mightbespace};
|
||||||
|
@ -97,7 +97,7 @@ impl Statement {
|
||||||
impl Statement {
|
impl Statement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Iterator;
|
use crate::dbs::Iterator;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
@ -30,7 +30,7 @@ pub struct CreateStatement {
|
||||||
impl CreateStatement {
|
impl CreateStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::algorithm::{algorithm, Algorithm};
|
use crate::sql::algorithm::{algorithm, Algorithm};
|
||||||
|
@ -48,7 +48,7 @@ pub enum DefineStatement {
|
||||||
impl DefineStatement {
|
impl DefineStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
@ -109,7 +109,7 @@ pub struct DefineNamespaceStatement {
|
||||||
impl DefineNamespaceStatement {
|
impl DefineNamespaceStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -156,7 +156,7 @@ pub struct DefineDatabaseStatement {
|
||||||
impl DefineDatabaseStatement {
|
impl DefineDatabaseStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -211,7 +211,7 @@ pub struct DefineLoginStatement {
|
||||||
impl DefineLoginStatement {
|
impl DefineLoginStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -330,7 +330,7 @@ pub struct DefineTokenStatement {
|
||||||
impl DefineTokenStatement {
|
impl DefineTokenStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -426,7 +426,7 @@ pub struct DefineScopeStatement {
|
||||||
impl DefineScopeStatement {
|
impl DefineScopeStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -562,7 +562,7 @@ pub struct DefineTableStatement {
|
||||||
impl DefineTableStatement {
|
impl DefineTableStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
@ -727,7 +727,7 @@ pub struct DefineEventStatement {
|
||||||
impl DefineEventStatement {
|
impl DefineEventStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -806,7 +806,7 @@ pub struct DefineFieldStatement {
|
||||||
impl DefineFieldStatement {
|
impl DefineFieldStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -944,7 +944,7 @@ pub struct DefineIndexStatement {
|
||||||
impl DefineIndexStatement {
|
impl DefineIndexStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Iterator;
|
use crate::dbs::Iterator;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
@ -31,7 +31,7 @@ pub struct DeleteStatement {
|
||||||
impl DeleteStatement {
|
impl DeleteStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::shouldbespace;
|
use crate::sql::comment::shouldbespace;
|
||||||
|
@ -21,7 +21,7 @@ pub struct IfelseStatement {
|
||||||
impl IfelseStatement {
|
impl IfelseStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::shouldbespace;
|
use crate::sql::comment::shouldbespace;
|
||||||
|
@ -26,7 +26,7 @@ pub enum InfoStatement {
|
||||||
impl InfoStatement {
|
impl InfoStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Iterator;
|
use crate::dbs::Iterator;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
@ -34,7 +34,7 @@ pub struct InsertStatement {
|
||||||
impl InsertStatement {
|
impl InsertStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::shouldbespace;
|
use crate::sql::comment::shouldbespace;
|
||||||
|
@ -19,7 +19,7 @@ pub struct KillStatement {
|
||||||
impl KillStatement {
|
impl KillStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::shouldbespace;
|
use crate::sql::comment::shouldbespace;
|
||||||
|
@ -27,7 +27,7 @@ pub struct LiveStatement {
|
||||||
impl LiveStatement {
|
impl LiveStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::shouldbespace;
|
use crate::sql::comment::shouldbespace;
|
||||||
|
@ -18,7 +18,7 @@ pub struct OutputStatement {
|
||||||
impl OutputStatement {
|
impl OutputStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Iterator;
|
use crate::dbs::Iterator;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
@ -37,7 +37,7 @@ pub struct RelateStatement {
|
||||||
impl RelateStatement {
|
impl RelateStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::base::{base, Base};
|
use crate::sql::base::{base, Base};
|
||||||
|
@ -32,7 +32,7 @@ pub enum RemoveStatement {
|
||||||
impl RemoveStatement {
|
impl RemoveStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
@ -93,7 +93,7 @@ pub struct RemoveNamespaceStatement {
|
||||||
impl RemoveNamespaceStatement {
|
impl RemoveNamespaceStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -147,7 +147,7 @@ pub struct RemoveDatabaseStatement {
|
||||||
impl RemoveDatabaseStatement {
|
impl RemoveDatabaseStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -202,7 +202,7 @@ pub struct RemoveLoginStatement {
|
||||||
impl RemoveLoginStatement {
|
impl RemoveLoginStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -277,7 +277,7 @@ pub struct RemoveTokenStatement {
|
||||||
impl RemoveTokenStatement {
|
impl RemoveTokenStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -351,7 +351,7 @@ pub struct RemoveScopeStatement {
|
||||||
impl RemoveScopeStatement {
|
impl RemoveScopeStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -402,7 +402,7 @@ pub struct RemoveTableStatement {
|
||||||
impl RemoveTableStatement {
|
impl RemoveTableStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -457,7 +457,7 @@ pub struct RemoveEventStatement {
|
||||||
impl RemoveEventStatement {
|
impl RemoveEventStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -515,7 +515,7 @@ pub struct RemoveFieldStatement {
|
||||||
impl RemoveFieldStatement {
|
impl RemoveFieldStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
@ -573,7 +573,7 @@ pub struct RemoveIndexStatement {
|
||||||
impl RemoveIndexStatement {
|
impl RemoveIndexStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
_doc: Option<&Value>,
|
_doc: Option<&Value>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Iterator;
|
use crate::dbs::Iterator;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
@ -59,7 +59,7 @@ impl SelectStatement {
|
||||||
impl SelectStatement {
|
impl SelectStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::comment::mightbespace;
|
use crate::sql::comment::mightbespace;
|
||||||
|
@ -23,7 +23,7 @@ pub struct SetStatement {
|
||||||
impl SetStatement {
|
impl SetStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Iterator;
|
use crate::dbs::Iterator;
|
||||||
use crate::dbs::Level;
|
use crate::dbs::Level;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Statement;
|
use crate::dbs::Statement;
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
@ -32,7 +32,7 @@ pub struct UpdateStatement {
|
||||||
impl UpdateStatement {
|
impl UpdateStatement {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::ctx::Context;
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::error::IResult;
|
use crate::sql::error::IResult;
|
||||||
|
@ -41,7 +40,7 @@ impl PartialOrd for Subquery {
|
||||||
impl Subquery {
|
impl Subquery {
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
|
@ -55,12 +54,9 @@ impl Subquery {
|
||||||
// Duplicate context
|
// Duplicate context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
// Add parent document
|
// Add parent document
|
||||||
if doc.is_some() {
|
if let Some(doc) = doc {
|
||||||
let doc = doc.unwrap().clone();
|
|
||||||
ctx.add_value("parent".into(), doc);
|
ctx.add_value("parent".into(), doc);
|
||||||
}
|
}
|
||||||
// Prepare context
|
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process subquery
|
// Process subquery
|
||||||
let res = v.compute(&ctx, &opt, txn, doc).await?;
|
let res = v.compute(&ctx, &opt, txn, doc).await?;
|
||||||
// Process result
|
// Process result
|
||||||
|
@ -81,12 +77,9 @@ impl Subquery {
|
||||||
// Duplicate context
|
// Duplicate context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
// Add parent document
|
// Add parent document
|
||||||
if doc.is_some() {
|
if let Some(doc) = doc {
|
||||||
let doc = doc.unwrap().clone();
|
|
||||||
ctx.add_value("parent".into(), doc);
|
ctx.add_value("parent".into(), doc);
|
||||||
}
|
}
|
||||||
// Prepare context
|
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process subquery
|
// Process subquery
|
||||||
match v.compute(&ctx, &opt, txn, doc).await? {
|
match v.compute(&ctx, &opt, txn, doc).await? {
|
||||||
Value::Array(mut v) => match v.len() {
|
Value::Array(mut v) => match v.len() {
|
||||||
|
@ -102,12 +95,9 @@ impl Subquery {
|
||||||
// Duplicate context
|
// Duplicate context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
// Add parent document
|
// Add parent document
|
||||||
if doc.is_some() {
|
if let Some(doc) = doc {
|
||||||
let doc = doc.unwrap().clone();
|
|
||||||
ctx.add_value("parent".into(), doc);
|
ctx.add_value("parent".into(), doc);
|
||||||
}
|
}
|
||||||
// Prepare context
|
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process subquery
|
// Process subquery
|
||||||
match v.compute(&ctx, &opt, txn, doc).await? {
|
match v.compute(&ctx, &opt, txn, doc).await? {
|
||||||
Value::Array(mut v) => match v.len() {
|
Value::Array(mut v) => match v.len() {
|
||||||
|
@ -123,12 +113,9 @@ impl Subquery {
|
||||||
// Duplicate context
|
// Duplicate context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
// Add parent document
|
// Add parent document
|
||||||
if doc.is_some() {
|
if let Some(doc) = doc {
|
||||||
let doc = doc.unwrap().clone();
|
|
||||||
ctx.add_value("parent".into(), doc);
|
ctx.add_value("parent".into(), doc);
|
||||||
}
|
}
|
||||||
// Prepare context
|
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process subquery
|
// Process subquery
|
||||||
match v.compute(&ctx, &opt, txn, doc).await? {
|
match v.compute(&ctx, &opt, txn, doc).await? {
|
||||||
Value::Array(mut v) => match v.len() {
|
Value::Array(mut v) => match v.len() {
|
||||||
|
@ -144,12 +131,9 @@ impl Subquery {
|
||||||
// Duplicate context
|
// Duplicate context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
// Add parent document
|
// Add parent document
|
||||||
if doc.is_some() {
|
if let Some(doc) = doc {
|
||||||
let doc = doc.unwrap().clone();
|
|
||||||
ctx.add_value("parent".into(), doc);
|
ctx.add_value("parent".into(), doc);
|
||||||
}
|
}
|
||||||
// Prepare context
|
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process subquery
|
// Process subquery
|
||||||
match v.compute(&ctx, &opt, txn, doc).await? {
|
match v.compute(&ctx, &opt, txn, doc).await? {
|
||||||
Value::Array(mut v) => match v.len() {
|
Value::Array(mut v) => match v.len() {
|
||||||
|
@ -165,12 +149,9 @@ impl Subquery {
|
||||||
// Duplicate context
|
// Duplicate context
|
||||||
let mut ctx = Context::new(ctx);
|
let mut ctx = Context::new(ctx);
|
||||||
// Add parent document
|
// Add parent document
|
||||||
if doc.is_some() {
|
if let Some(doc) = doc {
|
||||||
let doc = doc.unwrap().clone();
|
|
||||||
ctx.add_value("parent".into(), doc);
|
ctx.add_value("parent".into(), doc);
|
||||||
}
|
}
|
||||||
// Prepare context
|
|
||||||
let ctx = ctx.freeze();
|
|
||||||
// Process subquery
|
// Process subquery
|
||||||
match v.compute(&ctx, &opt, txn, doc).await? {
|
match v.compute(&ctx, &opt, txn, doc).await? {
|
||||||
Value::Array(mut v) => match v.len() {
|
Value::Array(mut v) => match v.len() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::array::Array;
|
use crate::sql::array::Array;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn array(
|
pub async fn array(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
path: &[Part],
|
path: &[Part],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
@ -7,7 +7,7 @@ use crate::sql::value::Value;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn clear(
|
pub async fn clear(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &Runtime,
|
_ctx: &Context<'_>,
|
||||||
_opt: &Options,
|
_opt: &Options,
|
||||||
_txn: &Transaction,
|
_txn: &Transaction,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::number::Number;
|
use crate::sql::number::Number;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn decrement(
|
pub async fn decrement(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
path: &[Part],
|
path: &[Part],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::part::Part;
|
use crate::sql::part::Part;
|
||||||
|
@ -12,7 +12,7 @@ static RID: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("id")]);
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn def(
|
pub async fn def(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
val: &Thing,
|
val: &Thing,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::array::Abolish;
|
use crate::sql::array::Abolish;
|
||||||
|
@ -15,7 +15,7 @@ impl Value {
|
||||||
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
||||||
pub async fn del(
|
pub async fn del(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
path: &[Part],
|
path: &[Part],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::field::{Field, Fields};
|
use crate::sql::field::{Field, Fields};
|
||||||
|
@ -16,7 +16,7 @@ impl Value {
|
||||||
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
path: &[Part],
|
path: &[Part],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::number::Number;
|
use crate::sql::number::Number;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn increment(
|
pub async fn increment(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
path: &[Part],
|
path: &[Part],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::part::Part;
|
use crate::sql::part::Part;
|
||||||
|
@ -8,7 +8,7 @@ use crate::sql::value::Value;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn merge(
|
pub async fn merge(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
val: &Value,
|
val: &Value,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::object::Object;
|
use crate::sql::object::Object;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn object(
|
pub async fn object(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
path: &[Part],
|
path: &[Part],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::array::Array;
|
use crate::sql::array::Array;
|
||||||
|
@ -9,7 +9,7 @@ use crate::sql::value::Value;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn patch(
|
pub async fn patch(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
val: &Array,
|
val: &Array,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
@ -7,7 +7,7 @@ use crate::sql::value::Value;
|
||||||
impl Value {
|
impl Value {
|
||||||
pub async fn replace(
|
pub async fn replace(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
val: &Value,
|
val: &Value,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::part::Next;
|
use crate::sql::part::Next;
|
||||||
|
@ -13,7 +13,7 @@ impl Value {
|
||||||
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
||||||
pub async fn set(
|
pub async fn set(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
path: &[Part],
|
path: &[Part],
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![allow(clippy::derive_ord_xor_partial_ord)]
|
#![allow(clippy::derive_ord_xor_partial_ord)]
|
||||||
|
|
||||||
|
use crate::ctx::Context;
|
||||||
use crate::dbs::Options;
|
use crate::dbs::Options;
|
||||||
use crate::dbs::Runtime;
|
|
||||||
use crate::dbs::Transaction;
|
use crate::dbs::Transaction;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::array::{array, Array};
|
use crate::sql::array::{array, Array};
|
||||||
|
@ -971,7 +971,7 @@ impl Value {
|
||||||
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
#[cfg_attr(not(feature = "parallel"), async_recursion(?Send))]
|
||||||
pub(crate) async fn compute(
|
pub(crate) async fn compute(
|
||||||
&self,
|
&self,
|
||||||
ctx: &Runtime,
|
ctx: &Context<'_>,
|
||||||
opt: &Options,
|
opt: &Options,
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
doc: Option<&'async_recursion Value>,
|
doc: Option<&'async_recursion Value>,
|
||||||
|
|
Loading…
Reference in a new issue