Ensure edge records are output as RELATE
statements in SQL export
Closes #1496
This commit is contained in:
parent
286bbef507
commit
c37d93bcb9
4 changed files with 29 additions and 5 deletions
|
@ -5,8 +5,10 @@ use crate::dbs::Transaction;
|
||||||
use crate::dbs::Workable;
|
use crate::dbs::Workable;
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
use crate::sql::paths::EDGE;
|
||||||
use crate::sql::paths::IN;
|
use crate::sql::paths::IN;
|
||||||
use crate::sql::paths::OUT;
|
use crate::sql::paths::OUT;
|
||||||
|
use crate::sql::value::Value;
|
||||||
use crate::sql::Dir;
|
use crate::sql::Dir;
|
||||||
|
|
||||||
impl<'a> Document<'a> {
|
impl<'a> Document<'a> {
|
||||||
|
@ -44,6 +46,7 @@ impl<'a> Document<'a> {
|
||||||
let key = crate::key::graph::new(opt.ns(), opt.db(), &r.tb, &r.id, i, rid);
|
let key = crate::key::graph::new(opt.ns(), opt.db(), &r.tb, &r.id, i, rid);
|
||||||
run.set(key, vec![]).await?;
|
run.set(key, vec![]).await?;
|
||||||
// Store the edges on the record
|
// Store the edges on the record
|
||||||
|
self.current.to_mut().set(ctx, opt, txn, &*EDGE, Value::True).await?;
|
||||||
self.current.to_mut().set(ctx, opt, txn, &*IN, l.clone().into()).await?;
|
self.current.to_mut().set(ctx, opt, txn, &*IN, l.clone().into()).await?;
|
||||||
self.current.to_mut().set(ctx, opt, txn, &*OUT, r.clone().into()).await?;
|
self.current.to_mut().set(ctx, opt, txn, &*OUT, r.clone().into()).await?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::doc::Document;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::dir::Dir;
|
use crate::sql::dir::Dir;
|
||||||
use crate::sql::edges::Edges;
|
use crate::sql::edges::Edges;
|
||||||
|
use crate::sql::paths::EDGE;
|
||||||
use crate::sql::paths::IN;
|
use crate::sql::paths::IN;
|
||||||
use crate::sql::paths::OUT;
|
use crate::sql::paths::OUT;
|
||||||
use crate::sql::statements::DeleteStatement;
|
use crate::sql::statements::DeleteStatement;
|
||||||
|
@ -38,8 +39,8 @@ impl<'a> Document<'a> {
|
||||||
let key = crate::key::thing::new(opt.ns(), opt.db(), &rid.tb, &rid.id);
|
let key = crate::key::thing::new(opt.ns(), opt.db(), &rid.tb, &rid.id);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Purge the record edges
|
// Purge the record edges
|
||||||
match (self.initial.pick(&*IN), self.initial.pick(&*OUT)) {
|
match (self.initial.pick(&*EDGE), self.initial.pick(&*IN), self.initial.pick(&*OUT)) {
|
||||||
(Value::Thing(ref l), Value::Thing(ref r)) => {
|
(Value::True, Value::Thing(ref l), Value::Thing(ref r)) => {
|
||||||
// Get temporary edge references
|
// Get temporary edge references
|
||||||
let (ref o, ref i) = (Dir::Out, Dir::In);
|
let (ref o, ref i) = (Dir::Out, Dir::In);
|
||||||
// Purge the left pointer edge
|
// Purge the left pointer edge
|
||||||
|
|
|
@ -7,7 +7,11 @@ use crate::key::thing;
|
||||||
use crate::kvs::cache::Cache;
|
use crate::kvs::cache::Cache;
|
||||||
use crate::kvs::cache::Entry;
|
use crate::kvs::cache::Entry;
|
||||||
use crate::sql;
|
use crate::sql;
|
||||||
|
use crate::sql::paths::EDGE;
|
||||||
|
use crate::sql::paths::IN;
|
||||||
|
use crate::sql::paths::OUT;
|
||||||
use crate::sql::thing::Thing;
|
use crate::sql::thing::Thing;
|
||||||
|
use crate::sql::Value;
|
||||||
use channel::Sender;
|
use channel::Sender;
|
||||||
use sql::permission::Permissions;
|
use sql::permission::Permissions;
|
||||||
use sql::statements::DefineDatabaseStatement;
|
use sql::statements::DefineDatabaseStatement;
|
||||||
|
@ -1461,12 +1465,26 @@ impl Transaction {
|
||||||
if n == i + 1 {
|
if n == i + 1 {
|
||||||
nxt = Some(k.clone());
|
nxt = Some(k.clone());
|
||||||
}
|
}
|
||||||
// Parse the key-value
|
// Parse the key and the value
|
||||||
let k: crate::key::thing::Thing = (&k).into();
|
let k: crate::key::thing::Thing = (&k).into();
|
||||||
let v: crate::sql::value::Value = (&v).into();
|
let v: crate::sql::value::Value = (&v).into();
|
||||||
let t = Thing::from((k.tb, k.id));
|
let t = Thing::from((k.tb, k.id));
|
||||||
// Write record
|
// Check if this is a graph edge
|
||||||
chn.send(bytes!(format!("UPDATE {} CONTENT {};", t, v))).await?;
|
match (v.pick(&*EDGE), v.pick(&*IN), v.pick(&*OUT)) {
|
||||||
|
// This is a graph edge record
|
||||||
|
(Value::True, Value::Thing(l), Value::Thing(r)) => {
|
||||||
|
let sql = format!(
|
||||||
|
"RELATE {} -> {} -> {} CONTENT {};",
|
||||||
|
l, t, r, v
|
||||||
|
);
|
||||||
|
chn.send(bytes!(sql)).await?;
|
||||||
|
}
|
||||||
|
// This is a normal record
|
||||||
|
_ => {
|
||||||
|
let sql = format!("UPDATE {} CONTENT {};", t, v);
|
||||||
|
chn.send(bytes!(sql)).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,3 +22,5 @@ pub static IN: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("in")]);
|
||||||
pub static OUT: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("out")]);
|
pub static OUT: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("out")]);
|
||||||
|
|
||||||
pub static META: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("__")]);
|
pub static META: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("__")]);
|
||||||
|
|
||||||
|
pub static EDGE: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("__")]);
|
||||||
|
|
Loading…
Reference in a new issue