2022-05-30 15:32:26 +00:00
|
|
|
use crate::ctx::Context;
|
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::dbs::Statement;
|
|
|
|
use crate::dbs::Workable;
|
|
|
|
use crate::doc::Document;
|
|
|
|
use crate::err::Error;
|
2023-01-17 10:41:34 +00:00
|
|
|
use crate::sql::paths::EDGE;
|
2022-06-17 22:55:09 +00:00
|
|
|
use crate::sql::paths::IN;
|
|
|
|
use crate::sql::paths::OUT;
|
2023-01-17 10:41:34 +00:00
|
|
|
use crate::sql::value::Value;
|
2022-06-15 07:50:59 +00:00
|
|
|
use crate::sql::Dir;
|
2022-05-30 15:32:26 +00:00
|
|
|
|
|
|
|
impl<'a> Document<'a> {
|
|
|
|
pub async fn edges(
|
2022-06-17 22:55:09 +00:00
|
|
|
&mut self,
|
2023-06-19 18:41:13 +00:00
|
|
|
ctx: &Context<'_>,
|
2022-05-30 15:32:26 +00:00
|
|
|
opt: &Options,
|
|
|
|
_stm: &Statement<'_>,
|
|
|
|
) -> Result<(), Error> {
|
2023-06-19 18:41:13 +00:00
|
|
|
// Clone transaction
|
2023-06-21 18:31:15 +00:00
|
|
|
let txn = ctx.try_clone_transaction()?;
|
2022-05-30 15:32:26 +00:00
|
|
|
// Check if the table is a view
|
2023-06-19 18:41:13 +00:00
|
|
|
if self.tb(opt, &txn).await?.drop {
|
2022-05-30 15:32:26 +00:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
// Claim transaction
|
2023-06-19 18:41:13 +00:00
|
|
|
let mut run = txn.lock().await;
|
2022-05-30 15:32:26 +00:00
|
|
|
// Get the record id
|
|
|
|
let rid = self.id.as_ref().unwrap();
|
|
|
|
// Store the record edges
|
|
|
|
if let Workable::Relate(l, r) = &self.extras {
|
2022-06-17 22:55:09 +00:00
|
|
|
// Get temporary edge references
|
|
|
|
let (ref o, ref i) = (Dir::Out, Dir::In);
|
2022-05-30 15:32:26 +00:00
|
|
|
// Store the left pointer edge
|
2022-06-17 22:55:09 +00:00
|
|
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &l.tb, &l.id, o, rid);
|
2022-06-15 07:50:59 +00:00
|
|
|
run.set(key, vec![]).await?;
|
2022-05-30 15:32:26 +00:00
|
|
|
// Store the left inner edge
|
2022-06-17 22:55:09 +00:00
|
|
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &rid.tb, &rid.id, i, l);
|
2022-06-15 07:50:59 +00:00
|
|
|
run.set(key, vec![]).await?;
|
2022-05-30 15:32:26 +00:00
|
|
|
// Store the right inner edge
|
2022-06-17 22:55:09 +00:00
|
|
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &rid.tb, &rid.id, o, r);
|
2022-06-15 07:50:59 +00:00
|
|
|
run.set(key, vec![]).await?;
|
2022-05-30 15:32:26 +00:00
|
|
|
// Store the right pointer edge
|
2022-06-17 22:55:09 +00:00
|
|
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &r.tb, &r.id, i, rid);
|
2022-06-15 07:50:59 +00:00
|
|
|
run.set(key, vec![]).await?;
|
2022-06-17 22:55:09 +00:00
|
|
|
// Store the edges on the record
|
2023-05-06 00:15:03 +00:00
|
|
|
self.current.to_mut().put(&*EDGE, Value::Bool(true));
|
|
|
|
self.current.to_mut().put(&*IN, l.clone().into());
|
|
|
|
self.current.to_mut().put(&*OUT, r.clone().into());
|
2022-05-30 15:32:26 +00:00
|
|
|
}
|
|
|
|
// Carry on
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|