Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
David Kosztka
Pod
Commits
543a935c
Commit
543a935c
authored
4 years ago
by
Bijun Li
Browse files
Options
Download
Email Patches
Plain Diff
Intermediate commit
parent
431cbe46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/api_model.rs
+11
-0
src/api_model.rs
src/internal_api.rs
+19
-0
src/internal_api.rs
with
30 additions
and
0 deletions
+30
-0
src/api_model.rs
+
11
-
0
View file @
543a935c
...
...
@@ -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
>
,
}
This diff is collapsed.
Click to expand it.
src/internal_api.rs
+
19
-
0
View file @
543a935c
...
...
@@ -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
(())
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment