2022-05-14 12:35:08 +00:00
|
|
|
use crate::ctx::Context;
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::dbs::Statement;
|
2022-05-30 15:32:26 +00:00
|
|
|
use crate::dbs::Workable;
|
2023-07-06 14:57:42 +00:00
|
|
|
use crate::dbs::{Operable, Transaction};
|
2023-07-20 12:56:32 +00:00
|
|
|
use crate::dbs::{Options, Processed};
|
2022-02-06 01:14:56 +00:00
|
|
|
use crate::doc::Document;
|
|
|
|
use crate::err::Error;
|
|
|
|
use crate::sql::value::Value;
|
2022-05-13 20:46:56 +00:00
|
|
|
use channel::Sender;
|
2022-02-06 01:14:56 +00:00
|
|
|
|
2022-02-13 19:03:00 +00:00
|
|
|
impl<'a> Document<'a> {
|
2022-12-30 08:23:19 +00:00
|
|
|
#[allow(dead_code)]
|
2022-05-01 22:25:53 +00:00
|
|
|
pub(crate) async fn compute(
|
2022-05-14 12:35:08 +00:00
|
|
|
ctx: &Context<'_>,
|
2022-05-13 20:46:56 +00:00
|
|
|
opt: &Options,
|
2023-07-06 14:57:42 +00:00
|
|
|
txn: &Transaction,
|
2022-05-13 20:46:56 +00:00
|
|
|
stm: &Statement<'_>,
|
2022-02-26 23:30:19 +00:00
|
|
|
chn: Sender<Result<Value, Error>>,
|
2023-07-20 12:56:32 +00:00
|
|
|
pro: Processed,
|
2022-02-26 23:30:19 +00:00
|
|
|
) -> Result<(), Error> {
|
2022-05-30 15:32:26 +00:00
|
|
|
// Setup a new workable
|
2023-07-20 12:56:32 +00:00
|
|
|
let ins = match pro.val {
|
2022-05-30 15:32:26 +00:00
|
|
|
Operable::Value(v) => (v, Workable::Normal),
|
|
|
|
Operable::Mergeable(v, o) => (v, Workable::Insert(o)),
|
|
|
|
Operable::Relatable(f, v, w) => (v, Workable::Relate(f, w)),
|
|
|
|
};
|
2022-02-23 13:56:09 +00:00
|
|
|
// Setup a new document
|
2023-07-20 12:56:32 +00:00
|
|
|
let mut doc = Document::new(pro.ir, pro.rid.as_ref(), pro.doc_id, &ins.0, ins.1);
|
2022-02-23 13:56:09 +00:00
|
|
|
// Process the statement
|
2022-02-26 23:30:19 +00:00
|
|
|
let res = match stm {
|
2023-07-06 14:57:42 +00:00
|
|
|
Statement::Select(_) => doc.select(ctx, opt, txn, stm).await,
|
|
|
|
Statement::Create(_) => doc.create(ctx, opt, txn, stm).await,
|
|
|
|
Statement::Update(_) => doc.update(ctx, opt, txn, stm).await,
|
|
|
|
Statement::Relate(_) => doc.relate(ctx, opt, txn, stm).await,
|
|
|
|
Statement::Delete(_) => doc.delete(ctx, opt, txn, stm).await,
|
|
|
|
Statement::Insert(_) => doc.insert(ctx, opt, txn, stm).await,
|
2023-02-22 18:04:20 +00:00
|
|
|
_ => unreachable!(),
|
2022-02-26 23:30:19 +00:00
|
|
|
};
|
|
|
|
// Send back the result
|
|
|
|
let _ = chn.send(res).await;
|
|
|
|
// Everything went ok
|
|
|
|
Ok(())
|
2022-02-06 01:14:56 +00:00
|
|
|
}
|
|
|
|
}
|