gqlite 1.2.2 → 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}/release.toml +2 -2
- 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 +34 -10
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/compiler/expression_analyser.rs +10 -4
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/compiler/variables_manager.rs +36 -39
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/compiler.rs +46 -41
- data/ext/gqlitedb/src/connection.rs +300 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/error.rs +113 -50
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/containers.rs +21 -26
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/edge.rs +3 -3
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/math.rs +3 -3
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/node.rs +2 -2
- data/ext/gqlitedb/src/functions/path.rs +75 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/scalar.rs +3 -3
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/string.rs +1 -1
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions/value.rs +7 -7
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/functions.rs +29 -31
- data/ext/gqlitedb/src/graph.rs +11 -0
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/interpreter/evaluators.rs +178 -224
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/interpreter/instructions.rs +8 -2
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/lib.rs +9 -5
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/parser/ast.rs +54 -76
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/parser/gql.pest +9 -4
- data/ext/{gqliterb/vendor/gqlitedb/src/parser/parser.rs → gqlitedb/src/parser/parser_impl.rs} +86 -34
- 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 +260 -170
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/store/sqlite.rs +157 -142
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/store.rs +30 -23
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/evaluators.rs +41 -85
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/store/redb.rs +12 -5
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/store/sqlite.rs +12 -5
- data/ext/{gqliterb/vendor/gqlitedb → gqlitedb}/src/tests/store.rs +106 -114
- 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 +22 -18
- data/ext/gqliterb/Cargo.toml +12 -34
- data/ext/gqliterb/src/lib.rs +67 -39
- 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 +146 -35
- 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 -1109
- data/ext/gqliterb/vendor/gqlitedb/Cargo.lock +0 -2060
- data/ext/gqliterb/vendor/gqlitedb/Cargo.toml +0 -132
- data/ext/gqliterb/vendor/gqlitedb/src/connection.rs +0 -208
- data/ext/gqliterb/vendor/gqlitedb/src/functions/path.rs +0 -48
- data/ext/gqliterb/vendor/gqlitedb/src/parser.rs +0 -4
- data/ext/gqliterb/vendor/gqlitedb/src/value.rs +0 -559
- /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}/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/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/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,5 +1,5 @@
|
|
1
1
|
use ccutils::sync::ArcRwLock;
|
2
|
-
use redb::{ReadableTable, ReadableTableMetadata};
|
2
|
+
use redb::{DatabaseError, ReadableDatabase as _, ReadableTable, ReadableTableMetadata as _};
|
3
3
|
use serde::{Deserialize, Serialize};
|
4
4
|
use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
|
5
5
|
|
@@ -16,9 +16,9 @@ use crate::{prelude::*, store::TransactionBoxable};
|
|
16
16
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
17
17
|
struct PersistentEdge
|
18
18
|
{
|
19
|
-
pub key:
|
20
|
-
pub source:
|
21
|
-
pub destination:
|
19
|
+
pub key: PersistentKey,
|
20
|
+
pub source: PersistentKey,
|
21
|
+
pub destination: PersistentKey,
|
22
22
|
pub labels: Vec<String>,
|
23
23
|
pub properties: value::ValueMap,
|
24
24
|
}
|
@@ -51,23 +51,54 @@ impl redb::Value for PersistentEdge
|
|
51
51
|
}
|
52
52
|
}
|
53
53
|
|
54
|
-
|
54
|
+
#[derive(Debug)]
|
55
|
+
enum PersistentNode<'a>
|
55
56
|
{
|
56
|
-
|
57
|
-
|
57
|
+
Reference(&'a graph::Node),
|
58
|
+
Value(graph::Node),
|
59
|
+
}
|
60
|
+
|
61
|
+
impl<'a> From<PersistentNode<'a>> for graph::Node
|
62
|
+
{
|
63
|
+
fn from(value: PersistentNode<'a>) -> Self
|
64
|
+
{
|
65
|
+
match value
|
66
|
+
{
|
67
|
+
PersistentNode::Reference(refe) => refe.to_owned(),
|
68
|
+
PersistentNode::Value(val) => val,
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
// ccutils::alias!(PersistentNode, graph::Node, derive: Debug, Deserialize, Serialize, Clone);
|
74
|
+
|
75
|
+
impl<'c> redb::Value for PersistentNode<'c>
|
76
|
+
{
|
77
|
+
type AsBytes<'a>
|
78
|
+
= Vec<u8>
|
79
|
+
where
|
80
|
+
Self: 'a;
|
81
|
+
type SelfType<'a>
|
82
|
+
= PersistentNode<'a>
|
83
|
+
where
|
84
|
+
Self: 'a;
|
58
85
|
fn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>
|
59
86
|
where
|
60
87
|
Self: 'b,
|
61
88
|
{
|
62
89
|
let mut data = Vec::<u8>::new();
|
63
|
-
|
90
|
+
match value
|
91
|
+
{
|
92
|
+
PersistentNode::Reference(refe) => ciborium::into_writer(refe, &mut data).unwrap(), // This unwrap should not happen, unless there is a bug
|
93
|
+
PersistentNode::Value(refe) => ciborium::into_writer(&refe, &mut data).unwrap(), // This unwrap should not happen, unless there is a bug
|
94
|
+
}
|
64
95
|
data
|
65
96
|
}
|
66
97
|
fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a>
|
67
98
|
where
|
68
99
|
Self: 'a,
|
69
100
|
{
|
70
|
-
ciborium::from_reader(data).unwrap() // This unwrap should not happen, unless there is a bug
|
101
|
+
PersistentNode::Value(ciborium::from_reader(data).unwrap()) // This unwrap should not happen, unless there is a bug
|
71
102
|
}
|
72
103
|
fn fixed_width() -> Option<usize>
|
73
104
|
{
|
@@ -79,15 +110,25 @@ impl redb::Value for graph::Node
|
|
79
110
|
}
|
80
111
|
}
|
81
112
|
|
82
|
-
|
113
|
+
ccutils::alias!(PersistentKey, graph::Key, derive: Debug, Deserialize, Serialize, PartialEq, Clone);
|
114
|
+
|
115
|
+
impl PersistentKey
|
116
|
+
{
|
117
|
+
fn to_owned_key(&self) -> graph::Key
|
118
|
+
{
|
119
|
+
*self.clone()
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
impl redb::Value for PersistentKey
|
83
124
|
{
|
84
125
|
type AsBytes<'a> = <u128 as redb::Value>::AsBytes<'a>;
|
85
|
-
type SelfType<'a> =
|
126
|
+
type SelfType<'a> = PersistentKey;
|
86
127
|
fn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>
|
87
128
|
where
|
88
129
|
Self: 'b,
|
89
130
|
{
|
90
|
-
u128::as_bytes(&value.uuid)
|
131
|
+
u128::as_bytes(&value.uuid())
|
91
132
|
}
|
92
133
|
fn fixed_width() -> Option<usize>
|
93
134
|
{
|
@@ -97,9 +138,7 @@ impl redb::Value for graph::Key
|
|
97
138
|
where
|
98
139
|
Self: 'a,
|
99
140
|
{
|
100
|
-
graph::Key
|
101
|
-
uuid: u128::from_bytes(data),
|
102
|
-
}
|
141
|
+
PersistentKey(graph::Key::new(u128::from_bytes(data)))
|
103
142
|
}
|
104
143
|
fn type_name() -> redb::TypeName
|
105
144
|
{
|
@@ -107,7 +146,7 @@ impl redb::Value for graph::Key
|
|
107
146
|
}
|
108
147
|
}
|
109
148
|
|
110
|
-
impl redb::Key for
|
149
|
+
impl redb::Key for PersistentKey
|
111
150
|
{
|
112
151
|
fn compare(data1: &[u8], data2: &[u8]) -> std::cmp::Ordering
|
113
152
|
{
|
@@ -147,10 +186,10 @@ impl EdgeIdResult
|
|
147
186
|
Some(v) => v,
|
148
187
|
None => match self.source_id
|
149
188
|
{
|
150
|
-
Some(v) => self.edge_data.destination == v,
|
189
|
+
Some(v) => *self.edge_data.destination == v,
|
151
190
|
None => match self.destination_id
|
152
191
|
{
|
153
|
-
Some(v) => self.edge_data.source == v,
|
192
|
+
Some(v) => *self.edge_data.source == v,
|
154
193
|
None => panic!("is_reversed"),
|
155
194
|
},
|
156
195
|
},
|
@@ -164,21 +203,6 @@ impl EdgeIdResult
|
|
164
203
|
// | | (_| | |_) | | __/
|
165
204
|
// |_|\__,_|_.__/|_|\___|
|
166
205
|
|
167
|
-
trait NodeTableExtension
|
168
|
-
{
|
169
|
-
fn get_node(&self, key: graph::Key) -> Result<graph::Node>;
|
170
|
-
}
|
171
|
-
|
172
|
-
impl<'txn> NodeTableExtension for redb::Table<'txn, graph::Key, &[u8]>
|
173
|
-
{
|
174
|
-
fn get_node(&self, key: graph::Key) -> Result<graph::Node>
|
175
|
-
{
|
176
|
-
let v = self.get_required(key, || InternalError::UnknownNode)?;
|
177
|
-
let c = ciborium::from_reader::<graph::Node, &[u8]>(&mut v.value())?;
|
178
|
-
Ok::<graph::Node, crate::prelude::ErrorType>(c)
|
179
|
-
}
|
180
|
-
}
|
181
|
-
|
182
206
|
trait TableExtension<K, V>
|
183
207
|
where
|
184
208
|
K: redb::Key + 'static,
|
@@ -188,10 +212,10 @@ where
|
|
188
212
|
&self,
|
189
213
|
key: impl std::borrow::Borrow<K::SelfType<'a>>,
|
190
214
|
f: impl FnOnce() -> TError,
|
191
|
-
) -> Result<redb::AccessGuard<V>>;
|
215
|
+
) -> Result<redb::AccessGuard<'_, V>>;
|
192
216
|
}
|
193
217
|
|
194
|
-
impl<
|
218
|
+
impl<K, V, T> TableExtension<K, V> for T
|
195
219
|
where
|
196
220
|
T: ReadableTable<K, V>,
|
197
221
|
K: redb::Key + 'static,
|
@@ -201,7 +225,7 @@ where
|
|
201
225
|
&self,
|
202
226
|
key: impl std::borrow::Borrow<K::SelfType<'a>>,
|
203
227
|
f: impl FnOnce() -> TError,
|
204
|
-
) -> Result<redb::AccessGuard<V>>
|
228
|
+
) -> Result<redb::AccessGuard<'_, V>>
|
205
229
|
{
|
206
230
|
self.get(key)?.ok_or_else(|| f().into())
|
207
231
|
}
|
@@ -217,6 +241,7 @@ where
|
|
217
241
|
#[derive(Debug)]
|
218
242
|
struct GraphInfo
|
219
243
|
{
|
244
|
+
#[allow(dead_code)]
|
220
245
|
name: String,
|
221
246
|
nodes_table: String,
|
222
247
|
edges_table: String,
|
@@ -242,23 +267,27 @@ impl GraphInfo
|
|
242
267
|
edges_destination_index,
|
243
268
|
}
|
244
269
|
}
|
245
|
-
fn nodes_table_definition<'a
|
270
|
+
fn nodes_table_definition<'a, 'b>(
|
271
|
+
&'a self,
|
272
|
+
) -> redb::TableDefinition<'a, PersistentKey, PersistentNode<'b>>
|
246
273
|
{
|
247
274
|
redb::TableDefinition::new(&self.nodes_table)
|
248
275
|
}
|
249
|
-
fn edges_table_definition<'a>(
|
276
|
+
fn edges_table_definition<'a>(
|
277
|
+
&'a self,
|
278
|
+
) -> redb::TableDefinition<'a, PersistentKey, PersistentEdge>
|
250
279
|
{
|
251
280
|
redb::TableDefinition::new(&self.edges_table)
|
252
281
|
}
|
253
282
|
fn edges_source_index_definition<'a>(
|
254
283
|
&'a self,
|
255
|
-
) -> redb::TableDefinition<'a,
|
284
|
+
) -> redb::TableDefinition<'a, PersistentKey, Vec<PersistentKey>>
|
256
285
|
{
|
257
286
|
redb::TableDefinition::new(&self.edges_source_index)
|
258
287
|
}
|
259
288
|
fn edges_destination_index_definition<'a>(
|
260
289
|
&'a self,
|
261
|
-
) -> redb::TableDefinition<'a,
|
290
|
+
) -> redb::TableDefinition<'a, PersistentKey, Vec<PersistentKey>>
|
262
291
|
{
|
263
292
|
redb::TableDefinition::new(&self.edges_destination_index)
|
264
293
|
}
|
@@ -314,19 +343,62 @@ type TransactionBox = store::TransactionBox<redb::ReadTransaction, redb::WriteTr
|
|
314
343
|
impl Store
|
315
344
|
{
|
316
345
|
/// Crate a new store, with a default graph
|
317
|
-
pub(crate) fn
|
346
|
+
pub(crate) fn open<P: AsRef<std::path::Path>>(path: P) -> Result<Store>
|
318
347
|
{
|
348
|
+
let redb_store = redb::Database::create(path.as_ref());
|
349
|
+
let redb_store = match redb_store
|
350
|
+
{
|
351
|
+
Ok(redb_store) => redb_store,
|
352
|
+
Err(e) => match e
|
353
|
+
{
|
354
|
+
DatabaseError::UpgradeRequired(v) =>
|
355
|
+
{
|
356
|
+
if v == 2
|
357
|
+
{
|
358
|
+
std::fs::copy(path.as_ref(), path.as_ref().with_extension("redb2.bak"))
|
359
|
+
.map_err(InternalError::IOError)?;
|
360
|
+
redb2::Database::create(path.as_ref())?.upgrade()?;
|
361
|
+
redb::Database::create(path.as_ref())?
|
362
|
+
}
|
363
|
+
else
|
364
|
+
{
|
365
|
+
Err(StoreError::InvalidFormat(format!(
|
366
|
+
"Unsupported redb version {}.",
|
367
|
+
v
|
368
|
+
)))?
|
369
|
+
}
|
370
|
+
}
|
371
|
+
o => Err(o)?,
|
372
|
+
},
|
373
|
+
};
|
319
374
|
let s = Self {
|
320
|
-
redb_store
|
375
|
+
redb_store,
|
321
376
|
graphs: Default::default(),
|
322
377
|
};
|
378
|
+
s.initialise()?;
|
379
|
+
Ok(s)
|
380
|
+
}
|
381
|
+
/// Crate a new store, with a default graph, in memory
|
382
|
+
pub(crate) fn in_memory() -> Result<Store>
|
383
|
+
{
|
384
|
+
let s = Self {
|
385
|
+
redb_store: redb::Database::builder()
|
386
|
+
.create_with_backend(redb::backends::InMemoryBackend::new())?,
|
387
|
+
graphs: Default::default(),
|
388
|
+
};
|
389
|
+
s.initialise()?;
|
390
|
+
Ok(s)
|
391
|
+
}
|
392
|
+
fn initialise(&self) -> Result<()>
|
393
|
+
{
|
323
394
|
use crate::store::Store;
|
324
|
-
let mut tx =
|
325
|
-
|
326
|
-
|
395
|
+
let mut tx = self.begin_write()?;
|
396
|
+
self.create_graph(&mut tx, "default", true)?;
|
397
|
+
self.set_metadata_value(&mut tx, "version", &consts::GQLITE_VERSION)?;
|
327
398
|
tx.close()?;
|
328
|
-
Ok(
|
399
|
+
Ok(())
|
329
400
|
}
|
401
|
+
#[allow(dead_code)]
|
330
402
|
fn get_metadata_from_table<TTable, TValue>(
|
331
403
|
&self,
|
332
404
|
table: TTable,
|
@@ -339,9 +411,10 @@ impl Store
|
|
339
411
|
let key = key.into();
|
340
412
|
let value = table
|
341
413
|
.get(&key)?
|
342
|
-
.ok_or_else(|| InternalError::MissingMetadata { key
|
414
|
+
.ok_or_else(|| InternalError::MissingMetadata { key })?;
|
343
415
|
Ok(ciborium::from_reader(value.value().as_slice())?)
|
344
416
|
}
|
417
|
+
#[allow(dead_code)]
|
345
418
|
fn get_metadata_value<T: for<'a> Deserialize<'a>>(
|
346
419
|
&self,
|
347
420
|
transaction: &mut TransactionBox,
|
@@ -415,8 +488,9 @@ impl Store
|
|
415
488
|
metadata_table.insert(&key, data)?;
|
416
489
|
Ok(())
|
417
490
|
}
|
418
|
-
fn get_graph_info(&self, graph_name:
|
491
|
+
fn get_graph_info(&self, graph_name: impl AsRef<str>) -> Result<Arc<GraphInfo>>
|
419
492
|
{
|
493
|
+
let graph_name = graph_name.as_ref();
|
420
494
|
let graphs = self.graphs.read()?;
|
421
495
|
let graph_info = graphs.get(graph_name);
|
422
496
|
match graph_info
|
@@ -425,7 +499,7 @@ impl Store
|
|
425
499
|
None =>
|
426
500
|
{
|
427
501
|
drop(graphs);
|
428
|
-
let graph_info = Arc::new(GraphInfo::new(graph_name));
|
502
|
+
let graph_info = Arc::new(GraphInfo::new(graph_name.to_owned()));
|
429
503
|
self
|
430
504
|
.graphs
|
431
505
|
.write()?
|
@@ -434,31 +508,32 @@ impl Store
|
|
434
508
|
}
|
435
509
|
}
|
436
510
|
}
|
437
|
-
fn select_nodes_from_table<
|
511
|
+
fn select_nodes_from_table<T>(
|
438
512
|
&self,
|
439
|
-
nodes_table: &
|
440
|
-
query: super::SelectNodeQuery,
|
513
|
+
nodes_table: &T,
|
514
|
+
query: &super::SelectNodeQuery,
|
441
515
|
) -> Result<Vec<crate::graph::Node>>
|
442
516
|
where
|
443
|
-
T: ReadableTable<
|
517
|
+
T: ReadableTable<PersistentKey, PersistentNode<'static>>,
|
444
518
|
{
|
445
|
-
let r = match query.keys
|
519
|
+
let r = match &query.keys
|
446
520
|
{
|
447
|
-
Some(keys) => Box::new(keys.
|
521
|
+
Some(keys) => Box::new(keys.iter().map(|key| {
|
448
522
|
Ok(
|
449
523
|
nodes_table
|
450
|
-
.get_required(key, || InternalError::UnknownNode)?
|
451
|
-
.value()
|
524
|
+
.get_required(PersistentKey(key.to_owned()), || InternalError::UnknownNode)?
|
525
|
+
.value()
|
526
|
+
.into(),
|
452
527
|
)
|
453
528
|
})) as Box<dyn Iterator<Item = Result<graph::Node>>>,
|
454
529
|
None => Box::new({
|
455
|
-
nodes_table.range::<
|
530
|
+
nodes_table.range::<PersistentKey>(..)?.map(|r| {
|
456
531
|
let (_, v) = r?;
|
457
|
-
Ok(v.value())
|
532
|
+
Ok(v.value().into())
|
458
533
|
})
|
459
534
|
}) as Box<dyn Iterator<Item = Result<graph::Node>>>,
|
460
535
|
};
|
461
|
-
let r = match query.labels
|
536
|
+
let r = match &query.labels
|
462
537
|
{
|
463
538
|
Some(labels) => Box::new(r.filter(move |n| match n
|
464
539
|
{
|
@@ -466,7 +541,7 @@ impl Store
|
|
466
541
|
{
|
467
542
|
for l in labels.iter()
|
468
543
|
{
|
469
|
-
if !n.labels.contains(l)
|
544
|
+
if !n.labels().contains(l)
|
470
545
|
{
|
471
546
|
return false;
|
472
547
|
}
|
@@ -477,7 +552,7 @@ impl Store
|
|
477
552
|
})) as Box<dyn Iterator<Item = Result<crate::graph::Node>>>,
|
478
553
|
None => Box::new(r) as Box<dyn Iterator<Item = Result<crate::graph::Node>>>,
|
479
554
|
};
|
480
|
-
let r = match query.properties
|
555
|
+
let r = match &query.properties
|
481
556
|
{
|
482
557
|
Some(properties) => Box::new(r.filter(move |n| match n
|
483
558
|
{
|
@@ -485,7 +560,7 @@ impl Store
|
|
485
560
|
{
|
486
561
|
for (k, v) in properties.iter()
|
487
562
|
{
|
488
|
-
match n.properties.get(k)
|
563
|
+
match n.properties().get(k)
|
489
564
|
{
|
490
565
|
Some(val) =>
|
491
566
|
{
|
@@ -519,9 +594,9 @@ impl Store
|
|
519
594
|
edges_destination_index: Rc<RefCell<TEdgesIndex>>,
|
520
595
|
) -> Result<Vec<super::EdgeResult>>
|
521
596
|
where
|
522
|
-
TEdges: ReadableTable<
|
523
|
-
TNodes: ReadableTable<
|
524
|
-
TEdgesIndex: ReadableTable<
|
597
|
+
TEdges: ReadableTable<PersistentKey, PersistentEdge>,
|
598
|
+
TNodes: ReadableTable<PersistentKey, PersistentNode<'static>>,
|
599
|
+
TEdgesIndex: ReadableTable<PersistentKey, Vec<PersistentKey>>,
|
525
600
|
{
|
526
601
|
let edges_uuid_indices = match directivity
|
527
602
|
{
|
@@ -539,12 +614,11 @@ impl Store
|
|
539
614
|
{
|
540
615
|
Some(keys) =>
|
541
616
|
{
|
542
|
-
for key in keys.
|
617
|
+
for key in keys.iter()
|
543
618
|
{
|
544
619
|
edges_raw.push(EdgeIdResult::new(
|
545
620
|
edges_table
|
546
|
-
.
|
547
|
-
.ok_or_else(|| InternalError::UnknownNode)?
|
621
|
+
.get_required(PersistentKey(key.to_owned()), || InternalError::UnknownNode)?
|
548
622
|
.value(),
|
549
623
|
Some(false),
|
550
624
|
None,
|
@@ -557,8 +631,7 @@ impl Store
|
|
557
631
|
if query.source.is_select_all() && query.destination.is_select_all()
|
558
632
|
{
|
559
633
|
edges_raw = edges_table
|
560
|
-
.range::<
|
561
|
-
.into_iter()
|
634
|
+
.range::<PersistentKey>(..)?
|
562
635
|
.map(|r| {
|
563
636
|
let (_, v) = r?;
|
564
637
|
Ok(EdgeIdResult::new(v.value(), Some(false), None, None))
|
@@ -572,33 +645,36 @@ impl Store
|
|
572
645
|
{
|
573
646
|
if !query.destination.is_select_all() && !query.source.is_select_all()
|
574
647
|
{
|
575
|
-
let dest_it =
|
576
|
-
self.select_nodes_from_table(&nodes_table, query.destination.clone())?;
|
648
|
+
let dest_it = self.select_nodes_from_table(&nodes_table, &query.destination)?;
|
577
649
|
let dest_it: Vec<graph::Key> = dest_it
|
578
650
|
.into_iter()
|
579
651
|
.map(|n| {
|
580
652
|
edges_destination_uuid_index
|
653
|
+
.as_ref()
|
581
654
|
.borrow()
|
582
|
-
.get_required(n.key, || InternalError::UnknownNode)
|
583
|
-
.map(|x|
|
655
|
+
.get_required(PersistentKey(n.key()), || InternalError::UnknownNode)
|
656
|
+
.map(|x| -> Vec<graph::Key> {
|
657
|
+
x.value().into_iter().map(|x| x.into()).collect()
|
658
|
+
})
|
584
659
|
})
|
585
660
|
.collect::<Result<Vec<_>>>()?
|
586
661
|
.into_iter()
|
587
662
|
.flatten()
|
588
663
|
.collect();
|
589
|
-
let nodes = self.select_nodes_from_table(&nodes_table, query.source
|
664
|
+
let nodes = self.select_nodes_from_table(&nodes_table, &query.source)?;
|
590
665
|
for n in nodes.iter()
|
591
666
|
{
|
592
|
-
let nkey = n.key;
|
667
|
+
let nkey = n.key();
|
593
668
|
for k in edges_source_uuid_index
|
669
|
+
.as_ref()
|
594
670
|
.borrow()
|
595
|
-
.get_required(nkey, || InternalError::UnknownNode)?
|
671
|
+
.get_required(PersistentKey(nkey), || InternalError::UnknownNode)?
|
596
672
|
.value()
|
597
673
|
.iter()
|
598
674
|
{
|
599
675
|
if dest_it.contains(k)
|
600
676
|
{
|
601
|
-
let uniq_k = (k
|
677
|
+
let uniq_k: (graph::Key, _, _) = ((**k), Some(nkey), None);
|
602
678
|
if !edge_ids.contains(&uniq_k)
|
603
679
|
{
|
604
680
|
edges_raw.push(EdgeIdResult::new(
|
@@ -617,18 +693,19 @@ impl Store
|
|
617
693
|
}
|
618
694
|
else if !query.source.is_select_all()
|
619
695
|
{
|
620
|
-
let nodes = self.select_nodes_from_table(&nodes_table, query.source
|
696
|
+
let nodes = self.select_nodes_from_table(&nodes_table, &query.source)?;
|
621
697
|
|
622
698
|
for n in nodes.into_iter()
|
623
699
|
{
|
624
|
-
let nkey = n.key;
|
700
|
+
let nkey = n.key();
|
625
701
|
for k in edges_source_uuid_index
|
702
|
+
.as_ref()
|
626
703
|
.borrow()
|
627
|
-
.get_required(nkey, || InternalError::UnknownNode)?
|
704
|
+
.get_required(PersistentKey(nkey), || InternalError::UnknownNode)?
|
628
705
|
.value()
|
629
706
|
.iter()
|
630
707
|
{
|
631
|
-
let uniq_k = (k.
|
708
|
+
let uniq_k = (k.to_owned_key(), Some(nkey), None);
|
632
709
|
if !edge_ids.contains(&uniq_k)
|
633
710
|
{
|
634
711
|
edges_raw.push(EdgeIdResult::new(
|
@@ -646,17 +723,18 @@ impl Store
|
|
646
723
|
}
|
647
724
|
else
|
648
725
|
{
|
649
|
-
let nodes = self.select_nodes_from_table(&nodes_table, query.destination
|
726
|
+
let nodes = self.select_nodes_from_table(&nodes_table, &query.destination)?;
|
650
727
|
for n in nodes.into_iter()
|
651
728
|
{
|
652
|
-
let nkey = n.key;
|
729
|
+
let nkey = n.key();
|
653
730
|
for k in edges_destination_uuid_index
|
731
|
+
.as_ref()
|
654
732
|
.borrow()
|
655
|
-
.get_required(nkey, || InternalError::UnknownNode)?
|
733
|
+
.get_required(PersistentKey(nkey), || InternalError::UnknownNode)?
|
656
734
|
.value()
|
657
735
|
.iter()
|
658
736
|
{
|
659
|
-
let uniq_k = (k.
|
737
|
+
let uniq_k = (k.to_owned_key(), None, Some(nkey));
|
660
738
|
if !edge_ids.contains(&uniq_k)
|
661
739
|
{
|
662
740
|
edges_raw.push(EdgeIdResult::new(
|
@@ -684,20 +762,26 @@ impl Store
|
|
684
762
|
let edge = v.edge_data;
|
685
763
|
|
686
764
|
let source = nodes_table
|
687
|
-
.
|
688
|
-
.
|
765
|
+
.get(edge.source)?
|
766
|
+
.ok_or(InternalError::UnknownNode)?
|
767
|
+
.value()
|
768
|
+
.into();
|
689
769
|
let destination = nodes_table
|
690
770
|
.get_required(edge.destination, || InternalError::UnknownNode)?
|
691
|
-
.value()
|
771
|
+
.value()
|
772
|
+
.into();
|
692
773
|
|
693
|
-
let edge = graph::
|
694
|
-
|
774
|
+
let edge = graph::Path::new(
|
775
|
+
edge.key.into(),
|
695
776
|
source,
|
777
|
+
edge.labels,
|
778
|
+
edge.properties,
|
696
779
|
destination,
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
780
|
+
);
|
781
|
+
super::EdgeResult {
|
782
|
+
path: edge,
|
783
|
+
reversed,
|
784
|
+
}
|
701
785
|
})
|
702
786
|
});
|
703
787
|
// Filter using the labels
|
@@ -709,7 +793,7 @@ impl Store
|
|
709
793
|
{
|
710
794
|
for l in labels.iter()
|
711
795
|
{
|
712
|
-
if !e.
|
796
|
+
if !e.path.labels().contains(l)
|
713
797
|
{
|
714
798
|
return false;
|
715
799
|
}
|
@@ -728,7 +812,7 @@ impl Store
|
|
728
812
|
{
|
729
813
|
for (k, v) in properties.iter()
|
730
814
|
{
|
731
|
-
match e.
|
815
|
+
match e.path.properties().get(k)
|
732
816
|
{
|
733
817
|
Some(val) =>
|
734
818
|
{
|
@@ -754,11 +838,11 @@ impl Store
|
|
754
838
|
r.filter(|e| {
|
755
839
|
if let Ok(e) = &e
|
756
840
|
{
|
757
|
-
query.is_match(&e.
|
841
|
+
query.is_match(&e.path)
|
758
842
|
}
|
759
843
|
else
|
760
844
|
{
|
761
|
-
|
845
|
+
true
|
762
846
|
}
|
763
847
|
})
|
764
848
|
.collect()
|
@@ -786,17 +870,18 @@ impl store::Store for Store
|
|
786
870
|
}
|
787
871
|
fn graphs_list(&self, transaction: &mut Self::TransactionBox) -> Result<Vec<String>>
|
788
872
|
{
|
789
|
-
self.get_metadata_value_or_else(transaction, "graphs".to_string(),
|
873
|
+
self.get_metadata_value_or_else(transaction, "graphs".to_string(), Vec::new)
|
790
874
|
}
|
791
875
|
fn create_graph(
|
792
876
|
&self,
|
793
877
|
transaction: &mut Self::TransactionBox,
|
794
|
-
graph_name:
|
878
|
+
graph_name: impl AsRef<str>,
|
795
879
|
ignore_if_exists: bool,
|
796
880
|
) -> Result<()>
|
797
881
|
{
|
882
|
+
let graph_name = graph_name.as_ref();
|
798
883
|
let mut graphs_list = self.graphs_list(transaction)?;
|
799
|
-
if graphs_list.
|
884
|
+
if graphs_list.iter().any(|s| s == graph_name)
|
800
885
|
{
|
801
886
|
if ignore_if_exists
|
802
887
|
{
|
@@ -824,16 +909,21 @@ impl store::Store for Store
|
|
824
909
|
|
825
910
|
self.graphs.write()?.insert(graph_name.to_owned(), gi);
|
826
911
|
}
|
827
|
-
graphs_list.push(graph_name.
|
912
|
+
graphs_list.push(graph_name.to_owned());
|
828
913
|
self.set_metadata_value(transaction, "graphs", &graphs_list)?;
|
829
914
|
|
830
915
|
Ok(())
|
831
916
|
}
|
832
|
-
fn
|
833
|
-
|
917
|
+
fn drop_graph(
|
918
|
+
&self,
|
919
|
+
transaction: &mut Self::TransactionBox,
|
920
|
+
graph_name: impl AsRef<str>,
|
921
|
+
if_exists: bool,
|
922
|
+
) -> Result<()>
|
834
923
|
{
|
924
|
+
let graph_name = graph_name.as_ref();
|
835
925
|
let mut graphs_list = self.graphs_list(transaction)?;
|
836
|
-
if graphs_list.
|
926
|
+
if graphs_list.iter().any(|s| s == graph_name)
|
837
927
|
{
|
838
928
|
{
|
839
929
|
let tx = transaction.try_into_write()?;
|
@@ -848,6 +938,10 @@ impl store::Store for Store
|
|
848
938
|
|
849
939
|
Ok(())
|
850
940
|
}
|
941
|
+
else if if_exists
|
942
|
+
{
|
943
|
+
Ok(())
|
944
|
+
}
|
851
945
|
else
|
852
946
|
{
|
853
947
|
Err(
|
@@ -859,10 +953,10 @@ impl store::Store for Store
|
|
859
953
|
}
|
860
954
|
}
|
861
955
|
/// Create nodes and add them to a graph
|
862
|
-
fn create_nodes<'a, T:
|
956
|
+
fn create_nodes<'a, T: IntoIterator<Item = &'a crate::graph::Node>>(
|
863
957
|
&self,
|
864
958
|
transaction: &mut Self::TransactionBox,
|
865
|
-
graph_name:
|
959
|
+
graph_name: impl AsRef<str>,
|
866
960
|
nodes_iter: T,
|
867
961
|
) -> Result<()>
|
868
962
|
{
|
@@ -874,9 +968,10 @@ impl store::Store for Store
|
|
874
968
|
transaction.open_table(graph_info.edges_destination_index_definition())?;
|
875
969
|
for x in nodes_iter
|
876
970
|
{
|
877
|
-
|
878
|
-
|
879
|
-
|
971
|
+
let pk = PersistentKey(x.key());
|
972
|
+
table.insert(&pk, PersistentNode::Reference(x))?;
|
973
|
+
table_source.insert(&pk, vec![])?;
|
974
|
+
table_destination.insert(&pk, vec![])?;
|
880
975
|
}
|
881
976
|
Ok(())
|
882
977
|
}
|
@@ -884,25 +979,26 @@ impl store::Store for Store
|
|
884
979
|
fn update_node(
|
885
980
|
&self,
|
886
981
|
transaction: &mut Self::TransactionBox,
|
887
|
-
graph_name:
|
982
|
+
graph_name: impl AsRef<str>,
|
888
983
|
node: &graph::Node,
|
889
984
|
) -> Result<()>
|
890
985
|
{
|
891
986
|
let graph_info = self.get_graph_info(graph_name)?;
|
892
987
|
let transaction = transaction.try_into_write()?;
|
893
988
|
let mut table = transaction.open_table(graph_info.nodes_table_definition())?;
|
894
|
-
table.insert(node.key, node)?;
|
989
|
+
table.insert(PersistentKey(node.key()), PersistentNode::Reference(node))?;
|
895
990
|
Ok(())
|
896
991
|
}
|
897
992
|
/// Delete nodes according to a given query
|
898
993
|
fn delete_nodes(
|
899
994
|
&self,
|
900
995
|
transaction: &mut Self::TransactionBox,
|
901
|
-
graph_name:
|
996
|
+
graph_name: impl AsRef<str>,
|
902
997
|
query: super::SelectNodeQuery,
|
903
998
|
detach: bool,
|
904
999
|
) -> Result<()>
|
905
1000
|
{
|
1001
|
+
let graph_name = graph_name.as_ref();
|
906
1002
|
let graph_info = self.get_graph_info(graph_name)?;
|
907
1003
|
|
908
1004
|
if query.is_select_all()
|
@@ -943,7 +1039,7 @@ impl store::Store for Store
|
|
943
1039
|
self
|
944
1040
|
.select_nodes(transaction, graph_name, query)?
|
945
1041
|
.into_iter()
|
946
|
-
.map(|x| x.key)
|
1042
|
+
.map(|x| x.key())
|
947
1043
|
.collect()
|
948
1044
|
};
|
949
1045
|
|
@@ -971,11 +1067,11 @@ impl store::Store for Store
|
|
971
1067
|
for key in node_keys.iter()
|
972
1068
|
{
|
973
1069
|
if !table_source
|
974
|
-
.get_required(key, || InternalError::UnknownNode)?
|
1070
|
+
.get_required(PersistentKey(key.to_owned()), || InternalError::UnknownNode)?
|
975
1071
|
.value()
|
976
1072
|
.is_empty()
|
977
1073
|
|| !table_destination
|
978
|
-
.get_required(key, || InternalError::UnknownNode)?
|
1074
|
+
.get_required(PersistentKey(key.to_owned()), || InternalError::UnknownNode)?
|
979
1075
|
.value()
|
980
1076
|
.is_empty()
|
981
1077
|
{
|
@@ -992,9 +1088,9 @@ impl store::Store for Store
|
|
992
1088
|
write_transaction.open_table(graph_info.edges_destination_index_definition())?;
|
993
1089
|
for key in node_keys.into_iter()
|
994
1090
|
{
|
995
|
-
table_nodes.remove(key)?;
|
996
|
-
table_source.remove(key)?;
|
997
|
-
table_destination.remove(key)?;
|
1091
|
+
table_nodes.remove(PersistentKey(key))?;
|
1092
|
+
table_source.remove(PersistentKey(key))?;
|
1093
|
+
table_destination.remove(PersistentKey(key))?;
|
998
1094
|
}
|
999
1095
|
}
|
1000
1096
|
Ok(())
|
@@ -1003,30 +1099,31 @@ impl store::Store for Store
|
|
1003
1099
|
fn select_nodes(
|
1004
1100
|
&self,
|
1005
1101
|
transaction: &mut Self::TransactionBox,
|
1006
|
-
graph_name:
|
1102
|
+
graph_name: impl AsRef<str>,
|
1007
1103
|
query: super::SelectNodeQuery,
|
1008
1104
|
) -> Result<Vec<crate::graph::Node>>
|
1009
1105
|
{
|
1106
|
+
let graph_name = graph_name.as_ref();
|
1010
1107
|
let graph_info = self.get_graph_info(graph_name)?;
|
1011
1108
|
match transaction
|
1012
1109
|
{
|
1013
1110
|
store::TransactionBox::Read(read) =>
|
1014
1111
|
{
|
1015
1112
|
let nodes_table = read.open_table(graph_info.nodes_table_definition())?;
|
1016
|
-
self.select_nodes_from_table(&nodes_table, query)
|
1113
|
+
self.select_nodes_from_table(&nodes_table, &query)
|
1017
1114
|
}
|
1018
1115
|
store::TransactionBox::Write(write) =>
|
1019
1116
|
{
|
1020
1117
|
let nodes_table = write.open_table(graph_info.nodes_table_definition())?;
|
1021
|
-
self.select_nodes_from_table(&nodes_table, query)
|
1118
|
+
self.select_nodes_from_table(&nodes_table, &query)
|
1022
1119
|
}
|
1023
1120
|
}
|
1024
1121
|
}
|
1025
1122
|
/// Add edge
|
1026
|
-
fn create_edges<'a, T:
|
1123
|
+
fn create_edges<'a, T: IntoIterator<Item = &'a crate::graph::SinglePath>>(
|
1027
1124
|
&self,
|
1028
1125
|
transaction: &mut Self::TransactionBox,
|
1029
|
-
graph_name:
|
1126
|
+
graph_name: impl AsRef<str>,
|
1030
1127
|
edges_iter: T,
|
1031
1128
|
) -> Result<()>
|
1032
1129
|
{
|
@@ -1040,62 +1137,59 @@ impl store::Store for Store
|
|
1040
1137
|
for x in edges_iter
|
1041
1138
|
{
|
1042
1139
|
let mut keys_source = table_source
|
1043
|
-
.remove(x.source.key)?
|
1140
|
+
.remove(PersistentKey(x.source().key()))?
|
1044
1141
|
.ok_or(InternalError::UnknownNode)?
|
1045
1142
|
.value();
|
1046
|
-
keys_source.push(x.key);
|
1143
|
+
keys_source.push(x.key().into());
|
1047
1144
|
let mut keys_destination = table_destination
|
1048
|
-
.remove(x.destination.key)?
|
1145
|
+
.remove(PersistentKey(x.destination().key()))?
|
1049
1146
|
.ok_or(InternalError::UnknownNode)?
|
1050
1147
|
.value();
|
1051
|
-
keys_destination.push(x.key);
|
1148
|
+
keys_destination.push(x.key().into());
|
1052
1149
|
|
1053
1150
|
table.insert(
|
1054
|
-
x.key,
|
1151
|
+
PersistentKey(x.key()),
|
1055
1152
|
&PersistentEdge {
|
1056
|
-
key: x.key,
|
1057
|
-
source: x.source.key,
|
1058
|
-
destination: x.destination.key,
|
1059
|
-
labels: x.labels.clone(),
|
1060
|
-
properties: x.properties.clone(),
|
1153
|
+
key: x.key().into(),
|
1154
|
+
source: x.source().key().into(),
|
1155
|
+
destination: x.destination().key().into(),
|
1156
|
+
labels: x.labels().clone(),
|
1157
|
+
properties: x.properties().clone(),
|
1061
1158
|
},
|
1062
1159
|
)?;
|
1063
|
-
table_source.insert(x.source.key, keys_source)?;
|
1064
|
-
table_destination.insert(x.destination.key, keys_destination)?;
|
1160
|
+
table_source.insert(PersistentKey(x.source().key()), keys_source)?;
|
1161
|
+
table_destination.insert(PersistentKey(x.destination().key()), keys_destination)?;
|
1065
1162
|
}
|
1066
1163
|
Ok(())
|
1067
1164
|
}
|
1068
1165
|
fn update_edge(
|
1069
1166
|
&self,
|
1070
1167
|
transaction: &mut Self::TransactionBox,
|
1071
|
-
graph_name:
|
1168
|
+
graph_name: impl AsRef<str>,
|
1072
1169
|
edge: &graph::Edge,
|
1073
1170
|
) -> Result<()>
|
1074
1171
|
{
|
1075
1172
|
let transaction = transaction.try_into_write()?;
|
1076
1173
|
let graph_info = self.get_graph_info(graph_name)?;
|
1077
1174
|
let mut table = transaction.open_table(graph_info.edges_table_definition())?;
|
1078
|
-
table
|
1079
|
-
edge.key,
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
labels: edge.labels.to_owned(),
|
1085
|
-
properties: edge.properties.to_owned(),
|
1086
|
-
},
|
1087
|
-
)?;
|
1175
|
+
let mut pe = table
|
1176
|
+
.get_required(&edge.key().into(), || InternalError::UnknownEdge)?
|
1177
|
+
.value();
|
1178
|
+
pe.labels = edge.labels().to_owned();
|
1179
|
+
pe.properties = edge.properties().to_owned();
|
1180
|
+
table.insert(PersistentKey(edge.key()), &pe)?;
|
1088
1181
|
Ok(())
|
1089
1182
|
}
|
1090
1183
|
/// Delete nodes according to a given query
|
1091
1184
|
fn delete_edges(
|
1092
1185
|
&self,
|
1093
1186
|
transaction: &mut Self::TransactionBox,
|
1094
|
-
graph_name:
|
1187
|
+
graph_name: impl AsRef<str>,
|
1095
1188
|
query: super::SelectEdgeQuery,
|
1096
1189
|
directivity: graph::EdgeDirectivity,
|
1097
1190
|
) -> Result<()>
|
1098
1191
|
{
|
1192
|
+
let graph_name = graph_name.as_ref();
|
1099
1193
|
let graph_info = self.get_graph_info(graph_name)?;
|
1100
1194
|
let edges = self.select_edges(transaction, graph_name, query, directivity)?;
|
1101
1195
|
|
@@ -1108,29 +1202,29 @@ impl store::Store for Store
|
|
1108
1202
|
|
1109
1203
|
for e in edges
|
1110
1204
|
{
|
1111
|
-
table.remove(e.
|
1205
|
+
table.remove(PersistentKey(e.path.key()))?;
|
1112
1206
|
let (sk, dk) = if e.reversed
|
1113
1207
|
{
|
1114
|
-
(e.
|
1208
|
+
(e.path.destination().key(), e.path.source().key())
|
1115
1209
|
}
|
1116
1210
|
else
|
1117
1211
|
{
|
1118
|
-
(e.
|
1212
|
+
(e.path.source().key(), e.path.destination().key())
|
1119
1213
|
};
|
1120
1214
|
|
1121
1215
|
let mut v = table_source
|
1122
|
-
.remove(sk)?
|
1216
|
+
.remove(PersistentKey(sk))?
|
1123
1217
|
.ok_or_else(|| InternalError::UnknownNode)?
|
1124
1218
|
.value();
|
1125
|
-
v.retain(|x| *x != e.
|
1126
|
-
table_source.insert(sk, v)?;
|
1219
|
+
v.retain(|x| *x != e.path.key().into());
|
1220
|
+
table_source.insert(PersistentKey(sk), v)?;
|
1127
1221
|
|
1128
1222
|
let mut v = table_destination
|
1129
|
-
.remove(dk)?
|
1223
|
+
.remove(PersistentKey(dk))?
|
1130
1224
|
.ok_or_else(|| InternalError::UnknownNode)?
|
1131
1225
|
.value();
|
1132
|
-
v.retain(|x| *x != e.
|
1133
|
-
table_destination.insert(dk, v)?;
|
1226
|
+
v.retain(|x| *x != e.path.key().into());
|
1227
|
+
table_destination.insert(PersistentKey(dk), v)?;
|
1134
1228
|
}
|
1135
1229
|
Ok(())
|
1136
1230
|
}
|
@@ -1138,7 +1232,7 @@ impl store::Store for Store
|
|
1138
1232
|
fn select_edges(
|
1139
1233
|
&self,
|
1140
1234
|
transaction: &mut Self::TransactionBox,
|
1141
|
-
graph_name:
|
1235
|
+
graph_name: impl AsRef<str>,
|
1142
1236
|
query: super::SelectEdgeQuery,
|
1143
1237
|
directivity: graph::EdgeDirectivity,
|
1144
1238
|
) -> Result<Vec<super::EdgeResult>>
|
@@ -1203,14 +1297,10 @@ impl store::Store for Store
|
|
1203
1297
|
let mut labels = Vec::new();
|
1204
1298
|
let mut properties_count = 0;
|
1205
1299
|
|
1206
|
-
for n in self.select_nodes(
|
1207
|
-
transaction,
|
1208
|
-
&"default".into(),
|
1209
|
-
super::SelectNodeQuery::select_all(),
|
1210
|
-
)?
|
1300
|
+
for n in self.select_nodes(transaction, "default", super::SelectNodeQuery::select_all())?
|
1211
1301
|
{
|
1212
1302
|
nodes_count += 1;
|
1213
|
-
for l in n.labels.iter()
|
1303
|
+
for l in n.labels().iter()
|
1214
1304
|
{
|
1215
1305
|
if !labels.contains(l)
|
1216
1306
|
{
|
@@ -1218,14 +1308,14 @@ impl store::Store for Store
|
|
1218
1308
|
}
|
1219
1309
|
}
|
1220
1310
|
properties_count += n
|
1221
|
-
.properties
|
1311
|
+
.properties()
|
1222
1312
|
.iter()
|
1223
1313
|
.filter(|(_, v)| **v != value::Value::Null)
|
1224
1314
|
.count();
|
1225
1315
|
}
|
1226
1316
|
for e in self.select_edges(
|
1227
1317
|
transaction,
|
1228
|
-
|
1318
|
+
"default",
|
1229
1319
|
super::SelectEdgeQuery::select_all(),
|
1230
1320
|
graph::EdgeDirectivity::Directed,
|
1231
1321
|
)?
|
@@ -1233,8 +1323,8 @@ impl store::Store for Store
|
|
1233
1323
|
edges_count += 1;
|
1234
1324
|
|
1235
1325
|
properties_count += e
|
1236
|
-
.
|
1237
|
-
.properties
|
1326
|
+
.path
|
1327
|
+
.properties()
|
1238
1328
|
.iter()
|
1239
1329
|
.filter(|(_, v)| **v != value::Value::Null)
|
1240
1330
|
.count();
|