gqlite 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/Cargo.toml +20 -0
- data/ext/gqlitedb/Cargo.toml +77 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/benches/common/pokec.rs +30 -20
- data/ext/gqlitedb/gqlite_bench_data/README.MD +6 -0
- data/ext/gqlitedb/gqlite_bench_data/scripts/generate_smaller_pokec.rb +85 -0
- data/ext/gqlitedb/gqlite_bench_data/scripts/to_efficient_pokec.rb +34 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/aggregators/arithmetic.rs +1 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/aggregators/stats.rs +27 -49
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/aggregators.rs +7 -7
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/capi.rs +10 -9
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/compiler/expression_analyser.rs +6 -4
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/compiler/variables_manager.rs +27 -31
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/compiler.rs +37 -41
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/connection.rs +42 -84
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/error.rs +105 -34
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/containers.rs +21 -26
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/edge.rs +2 -2
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/math.rs +2 -2
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/node.rs +1 -1
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/path.rs +15 -20
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/scalar.rs +2 -2
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/value.rs +6 -6
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions.rs +20 -20
- data/ext/gqlitedb/src/graph.rs +11 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/interpreter/evaluators.rs +160 -194
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/interpreter/instructions.rs +2 -1
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/lib.rs +9 -4
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/parser/ast.rs +44 -52
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/parser/gql.pest +1 -1
- data/ext/{gqliterb/vendor/gqlitedb/src/parser/parser.rs → gqlitedb/src/parser/parser_impl.rs} +50 -28
- data/ext/gqlitedb/src/parser.rs +4 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/prelude.rs +3 -2
- data/ext/gqlitedb/src/query_result.rs +88 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/store/redb.rs +226 -148
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/store/sqlite.rs +111 -128
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/store.rs +22 -22
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/evaluators.rs +32 -76
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/store.rs +95 -111
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/templates/ast.rs +29 -29
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/templates/programs.rs +4 -4
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/value/compare.rs +13 -20
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/value/contains.rs +2 -2
- data/ext/gqlitedb/src/value.rs +225 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/value_table.rs +15 -5
- data/ext/gqliterb/Cargo.toml +12 -35
- data/ext/gqliterb/src/lib.rs +60 -38
- data/ext/graphcore/Cargo.toml +19 -0
- data/ext/graphcore/README.MD +4 -0
- data/ext/graphcore/release.toml +1 -0
- data/ext/graphcore/src/error.rs +28 -0
- data/ext/{gqliterb/vendor/gqlitedb → graphcore}/src/graph.rs +134 -38
- data/ext/graphcore/src/lib.rs +16 -0
- data/ext/graphcore/src/prelude.rs +4 -0
- data/ext/{gqliterb/vendor/gqlitedb → graphcore}/src/serialize_with.rs +2 -2
- data/ext/graphcore/src/table.rs +272 -0
- data/ext/{gqliterb/vendor/gqlitedb → graphcore}/src/value/value_map.rs +44 -49
- data/ext/graphcore/src/value.rs +413 -0
- metadata +94 -83
- data/ext/gqliterb/.cargo/config.toml +0 -2
- data/ext/gqliterb/Cargo.lock +0 -1116
- data/ext/gqliterb/vendor/gqlitedb/Cargo.lock +0 -2115
- data/ext/gqliterb/vendor/gqlitedb/Cargo.toml +0 -138
- data/ext/gqliterb/vendor/gqlitedb/src/parser.rs +0 -4
- data/ext/gqliterb/vendor/gqlitedb/src/value.rs +0 -609
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/askama.toml +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/benches/common/mod.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/benches/pokec_divan.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/benches/pokec_iai.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/release.toml +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/aggregators/containers.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/aggregators/count.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/consts.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/string.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/interpreter/mod.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/store/pgql.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/compiler.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/parser.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/store/redb.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/store/sqlite.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/templates.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/utils.rs +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/call_stats.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/edge_count_for_node.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/edge_create.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/edge_delete.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/edge_delete_by_nodes.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/edge_select.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/edge_update.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/graph_create.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/graph_delete.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/metadata_create_table.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/metadata_get.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/metadata_set.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/node_create.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/node_delete.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/node_select.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/node_update.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/table_exists.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/upgrade_from_1_01.sql +0 -0
- /data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/templates/sql/sqlite/upgrade_graph_from_1_01.sql +0 -0
@@ -1,7 +1,5 @@
|
|
1
1
|
use std::{cell::RefCell, collections::HashSet, path::PathBuf};
|
2
2
|
|
3
|
-
use rusqlite;
|
4
|
-
|
5
3
|
use askama::Template;
|
6
4
|
use ccutils::pool::{self, Pool};
|
7
5
|
use rusqlite::{named_params, types::FromSql, OptionalExtension, ToSql};
|
@@ -19,23 +17,31 @@ use crate::{
|
|
19
17
|
// |_|\___/|_| |_| \___/|_| |_| |_|____/ \__, |_|
|
20
18
|
// |_|
|
21
19
|
|
22
|
-
|
20
|
+
ccutils::alias!(PersistentKey, graph::Key, derive: Debug, PartialEq);
|
21
|
+
|
22
|
+
impl rusqlite::ToSql for PersistentKey
|
23
23
|
{
|
24
24
|
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>>
|
25
25
|
{
|
26
26
|
Ok(rusqlite::types::ToSqlOutput::Owned(
|
27
|
-
rusqlite::types::Value::Blob(self.uuid.to_be_bytes().into()),
|
27
|
+
rusqlite::types::Value::Blob(self.uuid().to_be_bytes().into()),
|
28
28
|
))
|
29
29
|
}
|
30
30
|
}
|
31
31
|
|
32
|
-
impl rusqlite::types::FromSql for
|
32
|
+
impl rusqlite::types::FromSql for PersistentKey
|
33
33
|
{
|
34
34
|
fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self>
|
35
35
|
{
|
36
|
-
Ok(
|
37
|
-
|
38
|
-
|
36
|
+
Ok(u128::from_be_bytes(<[u8; 16]>::column_result(value)?).into())
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
impl From<u128> for PersistentKey
|
41
|
+
{
|
42
|
+
fn from(value: u128) -> Self
|
43
|
+
{
|
44
|
+
Self(graph::Key::new(value))
|
39
45
|
}
|
40
46
|
}
|
41
47
|
|
@@ -141,45 +147,45 @@ mod templates
|
|
141
147
|
#[template(path = "sql/sqlite/upgrade_graph_from_1_01.sql", escape = "none")]
|
142
148
|
pub(super) struct UpgradeGraphFrom1_01<'a>
|
143
149
|
{
|
144
|
-
pub graph_name: &'a
|
150
|
+
pub graph_name: &'a str,
|
145
151
|
}
|
146
152
|
#[derive(Template)]
|
147
153
|
#[template(path = "sql/sqlite/graph_create.sql", escape = "none")]
|
148
154
|
pub(super) struct GraphCreate<'a>
|
149
155
|
{
|
150
|
-
pub graph_name: &'a
|
156
|
+
pub graph_name: &'a str,
|
151
157
|
}
|
152
158
|
#[derive(Template)]
|
153
159
|
#[template(path = "sql/sqlite/graph_delete.sql", escape = "none")]
|
154
160
|
pub(super) struct GraphDelete<'a>
|
155
161
|
{
|
156
|
-
pub graph_name: &'a
|
162
|
+
pub graph_name: &'a str,
|
157
163
|
}
|
158
164
|
// Node related templates
|
159
165
|
#[derive(Template)]
|
160
166
|
#[template(path = "sql/sqlite/node_create.sql", escape = "none")]
|
161
167
|
pub(super) struct NodeCreate<'a>
|
162
168
|
{
|
163
|
-
pub graph_name: &'a
|
169
|
+
pub graph_name: &'a str,
|
164
170
|
}
|
165
171
|
#[derive(Template)]
|
166
172
|
#[template(path = "sql/sqlite/node_delete.sql", escape = "none")]
|
167
173
|
pub(super) struct NodeDelete<'a>
|
168
174
|
{
|
169
|
-
pub graph_name: &'a
|
175
|
+
pub graph_name: &'a str,
|
170
176
|
pub keys: &'a Vec<String>,
|
171
177
|
}
|
172
178
|
#[derive(Template)]
|
173
179
|
#[template(path = "sql/sqlite/node_update.sql", escape = "none")]
|
174
180
|
pub(super) struct NodeUpdate<'a>
|
175
181
|
{
|
176
|
-
pub graph_name: &'a
|
182
|
+
pub graph_name: &'a str,
|
177
183
|
}
|
178
184
|
#[derive(Template)]
|
179
185
|
#[template(path = "sql/sqlite/node_select.sql", escape = "none")]
|
180
186
|
pub(super) struct NodeSelect<'a>
|
181
187
|
{
|
182
|
-
pub graph_name: &'a
|
188
|
+
pub graph_name: &'a str,
|
183
189
|
pub has_keys: bool,
|
184
190
|
pub has_labels: bool,
|
185
191
|
pub has_properties: bool,
|
@@ -189,40 +195,40 @@ mod templates
|
|
189
195
|
#[template(path = "sql/sqlite/edge_count_for_node.sql", escape = "none")]
|
190
196
|
pub(super) struct EdgeCountForNode<'a>
|
191
197
|
{
|
192
|
-
pub graph_name: &'a
|
198
|
+
pub graph_name: &'a str,
|
193
199
|
pub keys: &'a Vec<String>,
|
194
200
|
}
|
195
201
|
#[derive(Template)]
|
196
202
|
#[template(path = "sql/sqlite/edge_create.sql", escape = "none")]
|
197
203
|
pub(super) struct EdgeCreate<'a>
|
198
204
|
{
|
199
|
-
pub graph_name: &'a
|
205
|
+
pub graph_name: &'a str,
|
200
206
|
}
|
201
207
|
#[derive(Template)]
|
202
208
|
#[template(path = "sql/sqlite/edge_delete_by_nodes.sql", escape = "none")]
|
203
209
|
pub(super) struct EdgeDeleteByNodes<'a>
|
204
210
|
{
|
205
|
-
pub graph_name: &'a
|
211
|
+
pub graph_name: &'a str,
|
206
212
|
pub keys: &'a Vec<String>,
|
207
213
|
}
|
208
214
|
#[derive(Template)]
|
209
215
|
#[template(path = "sql/sqlite/edge_delete.sql", escape = "none")]
|
210
216
|
pub(super) struct EdgeDelete<'a>
|
211
217
|
{
|
212
|
-
pub graph_name: &'a
|
218
|
+
pub graph_name: &'a str,
|
213
219
|
pub keys: &'a Vec<String>,
|
214
220
|
}
|
215
221
|
#[derive(Template)]
|
216
222
|
#[template(path = "sql/sqlite/edge_update.sql", escape = "none")]
|
217
223
|
pub(super) struct EdgeUpdate<'a>
|
218
224
|
{
|
219
|
-
pub graph_name: &'a
|
225
|
+
pub graph_name: &'a str,
|
220
226
|
}
|
221
227
|
#[derive(Template)]
|
222
228
|
#[template(path = "sql/sqlite/edge_select.sql", escape = "none")]
|
223
229
|
pub(super) struct EdgeSelect<'a>
|
224
230
|
{
|
225
|
-
pub graph_name: &'a
|
231
|
+
pub graph_name: &'a str,
|
226
232
|
pub is_undirected: bool,
|
227
233
|
pub table_suffix: &'a str,
|
228
234
|
pub has_edge_keys: bool,
|
@@ -239,7 +245,7 @@ mod templates
|
|
239
245
|
#[template(path = "sql/sqlite/call_stats.sql", escape = "none")]
|
240
246
|
pub(super) struct CallStats<'a>
|
241
247
|
{
|
242
|
-
pub graph_name: &'a
|
248
|
+
pub graph_name: &'a str,
|
243
249
|
}
|
244
250
|
}
|
245
251
|
|
@@ -251,14 +257,14 @@ mod templates
|
|
251
257
|
|
252
258
|
type TransactionBox = store::TransactionBox<ReadTransaction, WriteTransaction>;
|
253
259
|
|
254
|
-
fn hex(key:
|
260
|
+
fn hex(key: impl Into<graph::Key>) -> String
|
255
261
|
{
|
256
|
-
format!("{:032X}", key.uuid)
|
262
|
+
format!("{:032X}", key.into().uuid())
|
257
263
|
}
|
258
264
|
|
259
265
|
pub(crate) struct Store
|
260
266
|
{
|
261
|
-
connection: Pool<rusqlite::Connection,
|
267
|
+
connection: Pool<rusqlite::Connection, ErrorType>,
|
262
268
|
}
|
263
269
|
|
264
270
|
ccutils::assert_impl_all!(Store: Sync, Send);
|
@@ -330,7 +336,7 @@ impl Store
|
|
330
336
|
(),
|
331
337
|
)?;
|
332
338
|
self.set_metadata_value_json(&mut tx, "graphs", &Vec::<String>::new())?;
|
333
|
-
self.create_graph(&mut tx,
|
339
|
+
self.create_graph(&mut tx, "default", true)?;
|
334
340
|
}
|
335
341
|
self.set_metadata_value_json(&mut tx, "version", &consts::GQLITE_VERSION)?;
|
336
342
|
tx.close()?;
|
@@ -339,19 +345,14 @@ impl Store
|
|
339
345
|
fn upgrade_database(&self, transaction: &mut TransactionBox, from: utils::Version) -> Result<()>
|
340
346
|
{
|
341
347
|
use crate::store::Store;
|
342
|
-
|
348
|
+
if let (1, 0) = (from.major, from.minor)
|
343
349
|
{
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
)?;
|
351
|
-
self.set_metadata_value_json(transaction, "graphs", &vec!["default".to_string()])?;
|
352
|
-
}
|
353
|
-
_ =>
|
354
|
-
{}
|
350
|
+
// Create a metadata table and add the default graph.
|
351
|
+
transaction.get_connection().execute(
|
352
|
+
include_str!("../../templates/sql/sqlite/metadata_create_table.sql"),
|
353
|
+
(),
|
354
|
+
)?;
|
355
|
+
self.set_metadata_value_json(transaction, "graphs", &vec!["default".to_string()])?;
|
355
356
|
}
|
356
357
|
match (from.major, from.minor)
|
357
358
|
{
|
@@ -526,12 +527,13 @@ impl store::Store for Store
|
|
526
527
|
fn create_graph(
|
527
528
|
&self,
|
528
529
|
transaction: &mut Self::TransactionBox,
|
529
|
-
graph_name:
|
530
|
+
graph_name: impl AsRef<str>,
|
530
531
|
ignore_if_exists: bool,
|
531
532
|
) -> Result<()>
|
532
533
|
{
|
534
|
+
let graph_name = graph_name.as_ref();
|
533
535
|
let mut graphs_list = self.graphs_list(transaction)?;
|
534
|
-
if graphs_list.
|
536
|
+
if graphs_list.iter().any(|s| s == graph_name)
|
535
537
|
{
|
536
538
|
if ignore_if_exists
|
537
539
|
{
|
@@ -547,13 +549,9 @@ impl store::Store for Store
|
|
547
549
|
);
|
548
550
|
}
|
549
551
|
}
|
550
|
-
transaction
|
551
|
-
|
552
|
-
|
553
|
-
}
|
554
|
-
.render()?
|
555
|
-
.as_str(),
|
556
|
-
)?;
|
552
|
+
transaction
|
553
|
+
.get_connection()
|
554
|
+
.execute_batch(templates::GraphCreate { graph_name }.render()?.as_str())?;
|
557
555
|
graphs_list.push(graph_name.to_owned());
|
558
556
|
self.set_metadata_value_json(transaction, "graphs", &graphs_list)?;
|
559
557
|
Ok(())
|
@@ -561,20 +559,17 @@ impl store::Store for Store
|
|
561
559
|
fn drop_graph(
|
562
560
|
&self,
|
563
561
|
transaction: &mut Self::TransactionBox,
|
564
|
-
graph_name:
|
562
|
+
graph_name: impl AsRef<str>,
|
565
563
|
if_exists: bool,
|
566
564
|
) -> Result<()>
|
567
565
|
{
|
566
|
+
let graph_name = graph_name.as_ref();
|
568
567
|
let mut graphs_list = self.graphs_list(transaction)?;
|
569
|
-
if graphs_list.
|
568
|
+
if graphs_list.iter().any(|s| s == graph_name)
|
570
569
|
{
|
571
|
-
transaction
|
572
|
-
|
573
|
-
|
574
|
-
}
|
575
|
-
.render()?
|
576
|
-
.as_str(),
|
577
|
-
)?;
|
570
|
+
transaction
|
571
|
+
.get_connection()
|
572
|
+
.execute_batch(templates::GraphDelete { graph_name }.render()?.as_str())?;
|
578
573
|
graphs_list.retain(|x| x != graph_name);
|
579
574
|
self.set_metadata_value_json(transaction, "graphs", &graphs_list)?;
|
580
575
|
|
@@ -594,10 +589,10 @@ impl store::Store for Store
|
|
594
589
|
)
|
595
590
|
}
|
596
591
|
}
|
597
|
-
fn create_nodes<'a, T:
|
592
|
+
fn create_nodes<'a, T: IntoIterator<Item = &'a crate::graph::Node>>(
|
598
593
|
&self,
|
599
594
|
transaction: &mut Self::TransactionBox,
|
600
|
-
graph_name:
|
595
|
+
graph_name: impl AsRef<str>,
|
601
596
|
nodes_iter: T,
|
602
597
|
) -> Result<()>
|
603
598
|
{
|
@@ -605,14 +600,14 @@ impl store::Store for Store
|
|
605
600
|
{
|
606
601
|
transaction.get_connection().execute(
|
607
602
|
templates::NodeCreate {
|
608
|
-
graph_name: graph_name.
|
603
|
+
graph_name: graph_name.as_ref(),
|
609
604
|
}
|
610
605
|
.render()?
|
611
606
|
.as_str(),
|
612
607
|
(
|
613
|
-
x.key,
|
614
|
-
serde_json::to_string(
|
615
|
-
serde_json::to_string(
|
608
|
+
PersistentKey(x.key()),
|
609
|
+
serde_json::to_string(x.labels())?,
|
610
|
+
serde_json::to_string(x.properties())?,
|
616
611
|
),
|
617
612
|
)?;
|
618
613
|
}
|
@@ -621,18 +616,19 @@ impl store::Store for Store
|
|
621
616
|
fn delete_nodes(
|
622
617
|
&self,
|
623
618
|
transaction: &mut Self::TransactionBox,
|
624
|
-
graph_name:
|
619
|
+
graph_name: impl AsRef<str>,
|
625
620
|
query: store::SelectNodeQuery,
|
626
621
|
detach: bool,
|
627
622
|
) -> Result<()>
|
628
623
|
{
|
624
|
+
let graph_name = graph_name.as_ref();
|
629
625
|
let nodes = self.select_nodes(transaction, graph_name, query)?;
|
630
|
-
let nodes_keys: Vec<String> = nodes.into_iter().map(|x| hex(
|
626
|
+
let nodes_keys: Vec<String> = nodes.into_iter().map(|x| hex(x.key())).collect();
|
631
627
|
if detach
|
632
628
|
{
|
633
629
|
transaction.get_connection().execute(
|
634
630
|
templates::EdgeDeleteByNodes {
|
635
|
-
graph_name
|
631
|
+
graph_name,
|
636
632
|
keys: &nodes_keys,
|
637
633
|
}
|
638
634
|
.render()?
|
@@ -644,7 +640,7 @@ impl store::Store for Store
|
|
644
640
|
{
|
645
641
|
let count = transaction.get_connection().query_row(
|
646
642
|
templates::EdgeCountForNode {
|
647
|
-
graph_name
|
643
|
+
graph_name,
|
648
644
|
keys: &nodes_keys,
|
649
645
|
}
|
650
646
|
.render()?
|
@@ -659,7 +655,7 @@ impl store::Store for Store
|
|
659
655
|
}
|
660
656
|
transaction.get_connection().execute(
|
661
657
|
templates::NodeDelete {
|
662
|
-
graph_name
|
658
|
+
graph_name,
|
663
659
|
keys: &nodes_keys,
|
664
660
|
}
|
665
661
|
.render()?
|
@@ -671,20 +667,20 @@ impl store::Store for Store
|
|
671
667
|
fn update_node(
|
672
668
|
&self,
|
673
669
|
transaction: &mut Self::TransactionBox,
|
674
|
-
graph_name:
|
670
|
+
graph_name: impl AsRef<str>,
|
675
671
|
node: &crate::graph::Node,
|
676
672
|
) -> Result<()>
|
677
673
|
{
|
678
674
|
transaction.get_connection().execute(
|
679
675
|
templates::NodeUpdate {
|
680
|
-
graph_name:
|
676
|
+
graph_name: graph_name.as_ref(),
|
681
677
|
}
|
682
678
|
.render()?
|
683
679
|
.as_str(),
|
684
680
|
named_params! {
|
685
|
-
":key": node.key,
|
686
|
-
":labels": serde_json::to_string(
|
687
|
-
":properties": serde_json::to_string(
|
681
|
+
":key": PersistentKey(node.key()),
|
682
|
+
":labels": serde_json::to_string(node.labels())?,
|
683
|
+
":properties": serde_json::to_string(node.properties())?
|
688
684
|
},
|
689
685
|
)?;
|
690
686
|
Ok(())
|
@@ -692,13 +688,13 @@ impl store::Store for Store
|
|
692
688
|
fn select_nodes(
|
693
689
|
&self,
|
694
690
|
transaction: &mut Self::TransactionBox,
|
695
|
-
graph_name:
|
691
|
+
graph_name: impl AsRef<str>,
|
696
692
|
query: store::SelectNodeQuery,
|
697
693
|
) -> Result<Vec<crate::graph::Node>>
|
698
694
|
{
|
699
695
|
let mut prepared_query = transaction.get_connection().prepare(
|
700
696
|
templates::NodeSelect {
|
701
|
-
graph_name: graph_name.
|
697
|
+
graph_name: graph_name.as_ref(),
|
702
698
|
has_keys: query.keys.is_some(),
|
703
699
|
has_labels: query.labels.is_some(),
|
704
700
|
has_properties: query.properties.is_some(),
|
@@ -709,7 +705,7 @@ impl store::Store for Store
|
|
709
705
|
let mut bindings = Vec::<(&'static str, String)>::new();
|
710
706
|
if let Some(keys) = query.keys
|
711
707
|
{
|
712
|
-
let hex_keys = keys.iter().map(|key| hex(key)).collect::<Vec<_>>();
|
708
|
+
let hex_keys = keys.iter().map(|key| hex(*key)).collect::<Vec<_>>();
|
713
709
|
bindings.push((":keys", serde_json::to_string(&hex_keys)?));
|
714
710
|
}
|
715
711
|
if let Some(labels) = query.labels
|
@@ -730,21 +726,17 @@ impl store::Store for Store
|
|
730
726
|
let mut nodes: Vec<graph::Node> = Default::default();
|
731
727
|
while let Some(row) = it.next()?
|
732
728
|
{
|
733
|
-
let key = row.get(0)
|
729
|
+
let key: graph::Key = row.get::<_, PersistentKey>(0)?.into();
|
734
730
|
let labels = serde_json::from_str(&row.get::<_, String>(1)?)?;
|
735
731
|
let properties = serde_json::from_str(&row.get::<_, String>(2)?)?;
|
736
|
-
nodes.push(graph::Node
|
737
|
-
key,
|
738
|
-
labels,
|
739
|
-
properties,
|
740
|
-
});
|
732
|
+
nodes.push(graph::Node::new(key, labels, properties));
|
741
733
|
}
|
742
734
|
Ok(nodes)
|
743
735
|
}
|
744
|
-
fn create_edges<'a, T:
|
736
|
+
fn create_edges<'a, T: IntoIterator<Item = &'a crate::graph::SinglePath>>(
|
745
737
|
&self,
|
746
738
|
transaction: &mut Self::TransactionBox,
|
747
|
-
graph_name:
|
739
|
+
graph_name: impl AsRef<str>,
|
748
740
|
edges_iter: T,
|
749
741
|
) -> Result<()>
|
750
742
|
{
|
@@ -752,16 +744,16 @@ impl store::Store for Store
|
|
752
744
|
{
|
753
745
|
transaction.get_connection().execute(
|
754
746
|
templates::EdgeCreate {
|
755
|
-
graph_name: graph_name.
|
747
|
+
graph_name: graph_name.as_ref(),
|
756
748
|
}
|
757
749
|
.render()?
|
758
750
|
.as_str(),
|
759
751
|
(
|
760
|
-
x.key,
|
761
|
-
serde_json::to_string(
|
762
|
-
serde_json::to_string(
|
763
|
-
x.source.key,
|
764
|
-
x.destination.key,
|
752
|
+
PersistentKey(x.key()),
|
753
|
+
serde_json::to_string(x.labels())?,
|
754
|
+
serde_json::to_string(x.properties())?,
|
755
|
+
PersistentKey(x.source().key()),
|
756
|
+
PersistentKey(x.destination().key()),
|
765
757
|
),
|
766
758
|
)?;
|
767
759
|
}
|
@@ -770,16 +762,17 @@ impl store::Store for Store
|
|
770
762
|
fn delete_edges(
|
771
763
|
&self,
|
772
764
|
transaction: &mut Self::TransactionBox,
|
773
|
-
graph_name:
|
765
|
+
graph_name: impl AsRef<str>,
|
774
766
|
query: store::SelectEdgeQuery,
|
775
767
|
directivity: crate::graph::EdgeDirectivity,
|
776
768
|
) -> Result<()>
|
777
769
|
{
|
770
|
+
let graph_name = graph_name.as_ref();
|
778
771
|
let edges = self.select_edges(transaction, graph_name, query, directivity)?;
|
779
|
-
let edges_keys: Vec<String> = edges.into_iter().map(|x| hex(
|
772
|
+
let edges_keys: Vec<String> = edges.into_iter().map(|x| hex(x.path.key())).collect();
|
780
773
|
transaction.get_connection().execute(
|
781
774
|
templates::EdgeDelete {
|
782
|
-
graph_name
|
775
|
+
graph_name,
|
783
776
|
keys: &edges_keys,
|
784
777
|
}
|
785
778
|
.render()?
|
@@ -791,20 +784,20 @@ impl store::Store for Store
|
|
791
784
|
fn update_edge(
|
792
785
|
&self,
|
793
786
|
transaction: &mut Self::TransactionBox,
|
794
|
-
graph_name:
|
787
|
+
graph_name: impl AsRef<str>,
|
795
788
|
edge: &crate::graph::Edge,
|
796
789
|
) -> Result<()>
|
797
790
|
{
|
798
791
|
transaction.get_connection().execute(
|
799
792
|
templates::EdgeUpdate {
|
800
|
-
graph_name:
|
793
|
+
graph_name: graph_name.as_ref(),
|
801
794
|
}
|
802
795
|
.render()?
|
803
796
|
.as_str(),
|
804
797
|
named_params! {
|
805
|
-
":key": edge.key,
|
806
|
-
":labels": serde_json::to_string(
|
807
|
-
":properties": serde_json::to_string(
|
798
|
+
":key": PersistentKey(edge.key().to_owned()),
|
799
|
+
":labels": serde_json::to_string(edge.labels())?,
|
800
|
+
":properties": serde_json::to_string(edge.properties())?
|
808
801
|
},
|
809
802
|
)?;
|
810
803
|
Ok(())
|
@@ -812,7 +805,7 @@ impl store::Store for Store
|
|
812
805
|
fn select_edges(
|
813
806
|
&self,
|
814
807
|
transaction: &mut Self::TransactionBox,
|
815
|
-
graph_name:
|
808
|
+
graph_name: impl AsRef<str>,
|
816
809
|
query: store::SelectEdgeQuery,
|
817
810
|
directivity: crate::graph::EdgeDirectivity,
|
818
811
|
) -> Result<Vec<store::EdgeResult>>
|
@@ -828,9 +821,9 @@ impl store::Store for Store
|
|
828
821
|
};
|
829
822
|
let mut prepared_query = transaction.get_connection().prepare(
|
830
823
|
templates::EdgeSelect {
|
831
|
-
graph_name: graph_name,
|
824
|
+
graph_name: graph_name.as_ref(),
|
832
825
|
is_undirected,
|
833
|
-
table_suffix
|
826
|
+
table_suffix,
|
834
827
|
has_edge_keys: query.keys.is_some(),
|
835
828
|
has_edge_labels: query.labels.is_some(),
|
836
829
|
has_edge_properties: query.properties.is_some(),
|
@@ -850,7 +843,7 @@ impl store::Store for Store
|
|
850
843
|
// Edge queries
|
851
844
|
if let Some(keys) = query.keys
|
852
845
|
{
|
853
|
-
let hex_keys = keys.iter().map(|key| hex(
|
846
|
+
let hex_keys = keys.iter().map(|key| hex(*key)).collect::<Vec<_>>();
|
854
847
|
bindings.push((":edge_keys", serde_json::to_string(&hex_keys)?));
|
855
848
|
}
|
856
849
|
if let Some(labels) = query.labels
|
@@ -865,7 +858,7 @@ impl store::Store for Store
|
|
865
858
|
// Left queries
|
866
859
|
if let Some(keys) = query.source.keys
|
867
860
|
{
|
868
|
-
let hex_keys = keys.iter().map(|key| hex(
|
861
|
+
let hex_keys = keys.iter().map(|key| hex(*key)).collect::<Vec<_>>();
|
869
862
|
bindings.push((":n_left_keys", serde_json::to_string(&hex_keys)?));
|
870
863
|
}
|
871
864
|
if let Some(labels) = query.source.labels
|
@@ -880,7 +873,7 @@ impl store::Store for Store
|
|
880
873
|
// Right queries
|
881
874
|
if let Some(keys) = query.destination.keys
|
882
875
|
{
|
883
|
-
let hex_keys = keys.iter().map(|key| hex(
|
876
|
+
let hex_keys = keys.iter().map(|key| hex(*key)).collect::<Vec<_>>();
|
884
877
|
bindings.push((":n_right_keys", serde_json::to_string(&hex_keys)?));
|
885
878
|
}
|
886
879
|
if let Some(labels) = query.destination.labels
|
@@ -905,16 +898,16 @@ impl store::Store for Store
|
|
905
898
|
let mut edges_keys: HashSet<u128> = Default::default();
|
906
899
|
while let Some(row) = it.next()?
|
907
900
|
{
|
908
|
-
let edge_key:
|
909
|
-
let n_left_key = row.get(4)?;
|
910
|
-
let n_right_key = row.get(7)?;
|
901
|
+
let edge_key: PersistentKey = row.get(0)?;
|
902
|
+
let n_left_key: PersistentKey = row.get(4)?;
|
903
|
+
let n_right_key: PersistentKey = row.get(7)?;
|
911
904
|
|
912
905
|
// This ensure that if (a)-[]->(a) the edge is returned only once. But matching [a]-[]-[b] return the edge twice.
|
913
|
-
if n_left_key == n_right_key && edges_keys.contains(&edge_key.uuid)
|
906
|
+
if n_left_key == n_right_key && edges_keys.contains(&edge_key.uuid())
|
914
907
|
{
|
915
908
|
continue;
|
916
909
|
}
|
917
|
-
edges_keys.insert(edge_key.uuid);
|
910
|
+
edges_keys.insert(edge_key.uuid());
|
918
911
|
let edge_labels = serde_json::from_str(&row.get::<_, String>(1)?)?;
|
919
912
|
let edge_properties = serde_json::from_str(&row.get::<_, String>(2)?)?;
|
920
913
|
|
@@ -924,16 +917,8 @@ impl store::Store for Store
|
|
924
917
|
let n_right_labels = serde_json::from_str(&row.get::<_, String>(8)?)?;
|
925
918
|
let n_right_properties = serde_json::from_str(&row.get::<_, String>(9)?)?;
|
926
919
|
|
927
|
-
let source = graph::Node
|
928
|
-
|
929
|
-
labels: n_left_labels,
|
930
|
-
properties: n_left_properties,
|
931
|
-
};
|
932
|
-
let destination = graph::Node {
|
933
|
-
key: n_right_key,
|
934
|
-
labels: n_right_labels,
|
935
|
-
properties: n_right_properties,
|
936
|
-
};
|
920
|
+
let source = graph::Node::new(n_left_key.into(), n_left_labels, n_left_properties);
|
921
|
+
let destination = graph::Node::new(n_right_key.into(), n_right_labels, n_right_properties);
|
937
922
|
let reversed = row.get::<_, u32>(3)? == 1;
|
938
923
|
let (source, destination) = if reversed
|
939
924
|
{
|
@@ -945,13 +930,13 @@ impl store::Store for Store
|
|
945
930
|
};
|
946
931
|
|
947
932
|
edges.push(EdgeResult {
|
948
|
-
|
949
|
-
|
950
|
-
labels: edge_labels,
|
951
|
-
properties: edge_properties,
|
933
|
+
path: graph::Path::new(
|
934
|
+
edge_key.into(),
|
952
935
|
source,
|
936
|
+
edge_labels,
|
937
|
+
edge_properties,
|
953
938
|
destination,
|
954
|
-
|
939
|
+
),
|
955
940
|
reversed,
|
956
941
|
});
|
957
942
|
}
|
@@ -963,7 +948,7 @@ impl store::Store for Store
|
|
963
948
|
let (nodes_count, edges_count, labels_nodes_count, properties_count) =
|
964
949
|
transaction.get_connection().query_row(
|
965
950
|
templates::CallStats {
|
966
|
-
graph_name:
|
951
|
+
graph_name: "default",
|
967
952
|
}
|
968
953
|
.render()?
|
969
954
|
.as_str(),
|
@@ -990,13 +975,11 @@ mod tests
|
|
990
975
|
fn test_hex()
|
991
976
|
{
|
992
977
|
assert_eq!(
|
993
|
-
super::hex(
|
994
|
-
uuid: 18580062510968287067562660977870108180
|
995
|
-
}),
|
978
|
+
super::hex(graph::Key::new(18580062510968287067562660977870108180)),
|
996
979
|
"0DFA63CEE7484B0DBFC407697F77F614"
|
997
980
|
);
|
998
981
|
assert_eq!(
|
999
|
-
super::hex(
|
982
|
+
super::hex(graph::Key::new(0)),
|
1000
983
|
"00000000000000000000000000000000"
|
1001
984
|
);
|
1002
985
|
}
|