Commit 543a935c authored by Bijun Li's avatar Bijun Li
Browse files

Intermediate commit

parent 431cbe46
Showing with 30 additions and 0 deletions
+30 -0
......@@ -28,6 +28,15 @@ pub struct CreateEdge {
pub fields: HashMap<String, Value>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DeleteEdge {
pub _type: String,
pub _source: i64,
pub _target: i64,
#[serde(flatten)]
pub fields: HashMap<String, Value>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct BulkAction {
......@@ -39,4 +48,6 @@ pub struct BulkAction {
pub delete_items: Vec<i64>,
#[serde(default)]
pub create_edges: Vec<CreateEdge>,
#[serde(default)]
pub delete_edges: Vec<CreateEdge>,
}
......@@ -171,6 +171,17 @@ fn create_edge(tx: &Transaction, fields: HashMap<String, Value>) -> Result<()> {
execute_sql(tx, &sql, &fields)
}
/// Delete an edge when edge exists.
fn delete_edge(tx: &Transaction, fields: HashMap<String, Value>) -> Result<()> {
let fields: HashMap<String, Value> = fields
.into_iter()
.filter(|(k, v)| !is_array_or_object(v) && validate_field_name(k).is_ok())
.collect();
let mut sql = "DELETE FROM edges WHERE ".to_string();
let keys: Vec<_> = fields.keys().collect();
write_sql_body(&mut sql, &keys, ", ");
}
fn delete_item_tx(tx: &Transaction, uid: i64) -> Result<()> {
let mut fields = HashMap::new();
let time_now = Utc::now().timestamp_millis();
......@@ -198,6 +209,14 @@ fn bulk_action_tx(tx: &Transaction, bulk_action: BulkAction) -> Result<()> {
for edge_uid in bulk_action.delete_items {
delete_item_tx(tx, edge_uid)?;
}
for mut edge in bulk_action.delete_edges {
edge.fields
.insert("_source".to_string(), edge._source.into());
edge.fields
.insert("_target".to_string(), edge._target.into());
edge.fields.insert("_type".to_string(), edge._type.into());
delete_edge(tx, edge.fields)?;
}
Ok(())
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment