2022-05-30 15:32:26 +00:00
|
|
|
use crate::ctx::Context;
|
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::dbs::Statement;
|
|
|
|
use crate::dbs::Transaction;
|
|
|
|
use crate::dbs::Workable;
|
|
|
|
use crate::doc::Document;
|
|
|
|
use crate::err::Error;
|
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(
|
|
|
|
&self,
|
|
|
|
_ctx: &Context<'_>,
|
|
|
|
opt: &Options,
|
|
|
|
txn: &Transaction,
|
|
|
|
_stm: &Statement<'_>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
// Check if the table is a view
|
|
|
|
if self.tb(opt, txn).await?.drop {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
// Clone transaction
|
|
|
|
let run = txn.clone();
|
|
|
|
// Claim transaction
|
|
|
|
let mut run = run.lock().await;
|
|
|
|
// Get the record id
|
|
|
|
let rid = self.id.as_ref().unwrap();
|
|
|
|
// Store the record edges
|
|
|
|
if let Workable::Relate(l, r) = &self.extras {
|
|
|
|
// Store the left pointer edge
|
|
|
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &l.tb, &l.id, &Dir::Out, 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
|
|
|
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &rid.tb, &rid.id, &Dir::In, 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
|
|
|
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &rid.tb, &rid.id, &Dir::Out, 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
|
|
|
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &r.tb, &r.id, &Dir::In, rid);
|
2022-06-15 07:50:59 +00:00
|
|
|
run.set(key, vec![]).await?;
|
2022-05-30 15:32:26 +00:00
|
|
|
}
|
|
|
|
// Carry on
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|