gqlite 1.1.0 → 1.2.2

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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/ext/gqliterb/.cargo/config.toml +2 -0
  3. data/ext/gqliterb/Cargo.lock +1109 -0
  4. data/ext/gqliterb/Cargo.toml +43 -0
  5. data/ext/gqliterb/extconf.rb +4 -0
  6. data/ext/gqliterb/src/lib.rs +260 -0
  7. data/ext/gqliterb/vendor/gqlitedb/Cargo.lock +2060 -0
  8. data/ext/gqliterb/vendor/gqlitedb/Cargo.toml +132 -0
  9. data/ext/gqliterb/vendor/gqlitedb/askama.toml +3 -0
  10. data/ext/gqliterb/vendor/gqlitedb/benches/common/mod.rs +25 -0
  11. data/ext/gqliterb/vendor/gqlitedb/benches/common/pokec.rs +185 -0
  12. data/ext/gqliterb/vendor/gqlitedb/benches/pokec_divan.rs +137 -0
  13. data/ext/gqliterb/vendor/gqlitedb/benches/pokec_iai.rs +122 -0
  14. data/ext/gqliterb/vendor/gqlitedb/release.toml +7 -0
  15. data/ext/gqliterb/vendor/gqlitedb/src/aggregators/arithmetic.rs +96 -0
  16. data/ext/gqliterb/vendor/gqlitedb/src/aggregators/containers.rs +33 -0
  17. data/ext/gqliterb/vendor/gqlitedb/src/aggregators/count.rs +35 -0
  18. data/ext/gqliterb/vendor/gqlitedb/src/aggregators/stats.rs +168 -0
  19. data/ext/gqliterb/vendor/gqlitedb/src/aggregators.rs +74 -0
  20. data/ext/gqliterb/vendor/gqlitedb/src/capi.rs +236 -0
  21. data/ext/gqliterb/vendor/gqlitedb/src/compiler/expression_analyser.rs +427 -0
  22. data/ext/gqliterb/vendor/gqlitedb/src/compiler/variables_manager.rs +620 -0
  23. data/ext/gqliterb/vendor/gqlitedb/src/compiler.rs +1106 -0
  24. data/ext/gqliterb/vendor/gqlitedb/src/connection.rs +208 -0
  25. data/ext/gqliterb/vendor/gqlitedb/src/consts.rs +10 -0
  26. data/ext/gqliterb/vendor/gqlitedb/src/error.rs +621 -0
  27. data/ext/gqliterb/vendor/gqlitedb/src/functions/containers.rs +115 -0
  28. data/ext/gqliterb/vendor/gqlitedb/src/functions/edge.rs +20 -0
  29. data/ext/gqliterb/vendor/gqlitedb/src/functions/math.rs +44 -0
  30. data/ext/gqliterb/vendor/gqlitedb/src/functions/node.rs +16 -0
  31. data/ext/gqliterb/vendor/gqlitedb/src/functions/path.rs +48 -0
  32. data/ext/gqliterb/vendor/gqlitedb/src/functions/scalar.rs +86 -0
  33. data/ext/gqliterb/vendor/gqlitedb/src/functions/string.rs +28 -0
  34. data/ext/gqliterb/vendor/gqlitedb/src/functions/value.rs +99 -0
  35. data/ext/gqliterb/vendor/gqlitedb/src/functions.rs +412 -0
  36. data/ext/gqliterb/vendor/gqlitedb/src/graph.rs +268 -0
  37. data/ext/gqliterb/vendor/gqlitedb/src/interpreter/evaluators.rs +1788 -0
  38. data/ext/gqliterb/vendor/gqlitedb/src/interpreter/instructions.rs +262 -0
  39. data/ext/gqliterb/vendor/gqlitedb/src/interpreter/mod.rs +4 -0
  40. data/ext/gqliterb/vendor/gqlitedb/src/lib.rs +42 -0
  41. data/ext/gqliterb/vendor/gqlitedb/src/parser/ast.rs +625 -0
  42. data/ext/gqliterb/vendor/gqlitedb/src/parser/gql.pest +191 -0
  43. data/ext/gqliterb/vendor/gqlitedb/src/parser/parser.rs +1153 -0
  44. data/ext/gqliterb/vendor/gqlitedb/src/parser.rs +4 -0
  45. data/ext/gqliterb/vendor/gqlitedb/src/prelude.rs +8 -0
  46. data/ext/gqliterb/vendor/gqlitedb/src/serialize_with.rs +94 -0
  47. data/ext/gqliterb/vendor/gqlitedb/src/store/pgql.rs +121 -0
  48. data/ext/gqliterb/vendor/gqlitedb/src/store/redb.rs +1250 -0
  49. data/ext/gqliterb/vendor/gqlitedb/src/store/sqlite.rs +994 -0
  50. data/ext/gqliterb/vendor/gqlitedb/src/store.rs +432 -0
  51. data/ext/gqliterb/vendor/gqlitedb/src/tests/compiler.rs +92 -0
  52. data/ext/gqliterb/vendor/gqlitedb/src/tests/evaluators.rs +227 -0
  53. data/ext/gqliterb/vendor/gqlitedb/src/tests/parser.rs +81 -0
  54. data/ext/gqliterb/vendor/gqlitedb/src/tests/store/redb.rs +39 -0
  55. data/ext/gqliterb/vendor/gqlitedb/src/tests/store/sqlite.rs +39 -0
  56. data/ext/gqliterb/vendor/gqlitedb/src/tests/store.rs +462 -0
  57. data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/ast.rs +356 -0
  58. data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/programs.rs +455 -0
  59. data/ext/gqliterb/vendor/gqlitedb/src/tests/templates.rs +2 -0
  60. data/ext/gqliterb/vendor/gqlitedb/src/tests.rs +39 -0
  61. data/ext/gqliterb/vendor/gqlitedb/src/utils.rs +28 -0
  62. data/ext/gqliterb/vendor/gqlitedb/src/value/compare.rs +212 -0
  63. data/ext/gqliterb/vendor/gqlitedb/src/value/contains.rs +47 -0
  64. data/ext/gqliterb/vendor/gqlitedb/src/value/value_map.rs +298 -0
  65. data/ext/gqliterb/vendor/gqlitedb/src/value.rs +559 -0
  66. data/ext/gqliterb/vendor/gqlitedb/src/value_table.rs +616 -0
  67. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/call_stats.sql +22 -0
  68. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_count_for_node.sql +3 -0
  69. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_create.sql +6 -0
  70. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete.sql +1 -0
  71. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete_by_nodes.sql +2 -0
  72. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_select.sql +139 -0
  73. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_update.sql +4 -0
  74. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_create.sql +16 -0
  75. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_delete.sql +3 -0
  76. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_create_table.sql +1 -0
  77. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_get.sql +1 -0
  78. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_set.sql +1 -0
  79. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_create.sql +1 -0
  80. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_delete.sql +1 -0
  81. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_select.sql +42 -0
  82. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_update.sql +4 -0
  83. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/table_exists.sql +5 -0
  84. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_from_1_01.sql +2 -0
  85. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_graph_from_1_01.sql +65 -0
  86. data/lib/gqlite.rb +1 -75
  87. metadata +118 -25
  88. data/ext/gqlite/extconf.rb +0 -21
  89. data/ext/gqlite/gqlite-amalgamate.cpp +0 -9599
  90. data/ext/gqlite/gqlite-c.h +0 -95
  91. data/ext/gqlite/gqlite.h +0 -141
@@ -0,0 +1,262 @@
1
+ use crate::{prelude::*, value_table::ColId};
2
+
3
+ #[derive(Debug)]
4
+ pub(crate) enum Instruction
5
+ {
6
+ CreateNodeLiteral
7
+ {
8
+ labels: Vec<String>,
9
+ },
10
+ CreateEdgeLiteral
11
+ {
12
+ labels: Vec<String>,
13
+ },
14
+ CreateNodeQuery
15
+ {
16
+ labels: Vec<String>,
17
+ },
18
+ CreateEdgeQuery
19
+ {
20
+ labels: Vec<String>,
21
+ },
22
+ FunctionCall
23
+ {
24
+ function: functions::Function,
25
+ arguments_count: usize,
26
+ },
27
+ Push
28
+ {
29
+ value: value::Value,
30
+ },
31
+ GetVariable
32
+ {
33
+ col_id: value_table::ColId,
34
+ },
35
+ GetParameter
36
+ {
37
+ name: String,
38
+ },
39
+ CreateArray
40
+ {
41
+ length: usize,
42
+ },
43
+ CreateMap
44
+ {
45
+ keys: Vec<String>,
46
+ },
47
+ IndexAccess,
48
+ RangeAccess
49
+ {
50
+ start: bool,
51
+ end: bool,
52
+ },
53
+ MemberAccess
54
+ {
55
+ path: Vec<String>,
56
+ },
57
+ Duplicate,
58
+ Rot3, // If a is the top of the stack, then a b c -> b c a
59
+ InverseRot3, // If a is the top of the stack, then a b c -> c a b
60
+ Swap,
61
+ Drop,
62
+ AndBinaryOperator,
63
+ OrBinaryOperator,
64
+ XorBinaryOperator,
65
+ NegationUnaryOperator,
66
+ NotUnaryOperator,
67
+ IsNullUnaryOperator,
68
+ EqualBinaryOperator,
69
+ NotEqualBinaryOperator,
70
+ InferiorBinaryOperator,
71
+ SuperiorBinaryOperator,
72
+ InferiorEqualBinaryOperator,
73
+ SuperiorEqualBinaryOperator,
74
+ InBinaryOperator,
75
+ NotInBinaryOperator,
76
+ AdditionBinaryOperator,
77
+ SubtractionBinaryOperator,
78
+ MultiplicationBinaryOperator,
79
+ DivisionBinaryOperator,
80
+ ModuloBinaryOperator,
81
+ }
82
+
83
+ pub(crate) type Instructions = Vec<Instruction>;
84
+
85
+ #[derive(Debug)]
86
+ pub(crate) struct CreateAction
87
+ {
88
+ pub(crate) instructions: Instructions,
89
+ pub(crate) variables: Vec<Option<ColId>>,
90
+ }
91
+
92
+ #[derive(Debug)]
93
+ pub(crate) enum BlockMatch
94
+ {
95
+ MatchNode
96
+ {
97
+ instructions: Instructions,
98
+ variable: Option<ColId>,
99
+ filter: Instructions,
100
+ },
101
+ MatchEdge
102
+ {
103
+ instructions: Instructions,
104
+ left_variable: Option<ColId>,
105
+ edge_variable: Option<ColId>,
106
+ right_variable: Option<ColId>,
107
+ path_variable: Option<ColId>,
108
+ filter: Instructions,
109
+ directivity: graph::EdgeDirectivity,
110
+ },
111
+ }
112
+
113
+ #[derive(Debug)]
114
+ pub(crate) struct RWAggregation
115
+ {
116
+ pub(crate) init_instructions: Instructions,
117
+ pub(crate) argument_instructions: Instructions,
118
+ pub(crate) aggregator: aggregators::Aggregator,
119
+ }
120
+
121
+ /// R(eturn)W(ith)Expression are expressions computed in Return or With blocks.
122
+ #[derive(Debug)]
123
+ pub(crate) struct RWExpression
124
+ {
125
+ /// Id of the column where to get the value from
126
+ pub(crate) col_id: ColId,
127
+ /// Instructions to compute this expression
128
+ pub(crate) instructions: Instructions,
129
+ /// Potential aggregations used by this expression
130
+ pub(crate) aggregations: Vec<(value_table::ColId, RWAggregation)>,
131
+ }
132
+
133
+ /// Update one node/edge.
134
+ #[derive(Debug)]
135
+ pub(crate) enum UpdateOne
136
+ {
137
+ SetProperty
138
+ {
139
+ /// Target is the column containing the node/edge to modify
140
+ target: ColId,
141
+ path: Vec<String>,
142
+ instructions: Instructions,
143
+ },
144
+ AddProperty
145
+ {
146
+ /// Target is the column containing the node/edge to modify
147
+ target: ColId,
148
+ path: Vec<String>,
149
+ instructions: Instructions,
150
+ },
151
+ RemoveProperty
152
+ {
153
+ /// Target is the column containing the node/edge to modify
154
+ target: ColId,
155
+ path: Vec<String>,
156
+ },
157
+ AddLabels
158
+ {
159
+ /// Target is the column containing the node/edge to modify
160
+ target: ColId,
161
+ labels: Vec<String>,
162
+ },
163
+ RemoveLabels
164
+ {
165
+ /// Target is the column containing the node/edge to modify
166
+ target: ColId,
167
+ labels: Vec<String>,
168
+ },
169
+ }
170
+
171
+ #[derive(Debug)]
172
+ pub(crate) struct OrderBy
173
+ {
174
+ pub asc: bool,
175
+ pub instructions: Instructions,
176
+ }
177
+
178
+ #[derive(Debug)]
179
+ pub(crate) struct Modifiers
180
+ {
181
+ pub limit: Option<Instructions>,
182
+ pub skip: Option<Instructions>,
183
+ pub order_by: Vec<OrderBy>,
184
+ }
185
+
186
+ #[derive(Debug)]
187
+ pub(crate) struct VariablesSizes
188
+ {
189
+ /// How many variables are persistent, after the block has been executed.
190
+ pub persistent_variables: usize,
191
+ /// How many temporary variables are used by the block.
192
+ pub temporary_variables: usize,
193
+ }
194
+
195
+ impl VariablesSizes
196
+ {
197
+ /// Return the total size, `persistent+temporary` variables
198
+ pub(crate) fn total_size(&self) -> usize
199
+ {
200
+ self.temporary_variables + self.persistent_variables
201
+ }
202
+ }
203
+
204
+ #[derive(Debug)]
205
+ pub(crate) enum Block
206
+ {
207
+ CreateGraph
208
+ {
209
+ name: String
210
+ },
211
+ UseGraph
212
+ {
213
+ name: String
214
+ },
215
+ Create
216
+ {
217
+ actions: Vec<CreateAction>,
218
+ variables_size: VariablesSizes,
219
+ },
220
+ BlockMatch
221
+ {
222
+ blocks: Vec<BlockMatch>,
223
+ filter: Instructions,
224
+ optional: bool,
225
+ variables_size: VariablesSizes,
226
+ },
227
+ Return
228
+ {
229
+ variables: Vec<(String, RWExpression)>,
230
+ filter: Instructions,
231
+ modifiers: Modifiers,
232
+ variables_size: VariablesSizes,
233
+ },
234
+ Call
235
+ {
236
+ arguments: Instructions,
237
+ name: String,
238
+ },
239
+ With
240
+ {
241
+ variables: Vec<RWExpression>,
242
+ filter: Instructions,
243
+ modifiers: Modifiers,
244
+ variables_size: VariablesSizes,
245
+ },
246
+ Unwind
247
+ {
248
+ col_id: ColId,
249
+ instructions: Instructions,
250
+ variables_size: VariablesSizes,
251
+ },
252
+ Delete
253
+ {
254
+ detach: bool,
255
+ instructions: Vec<Instructions>,
256
+ },
257
+ Update
258
+ {
259
+ updates: Vec<UpdateOne>,
260
+ variables_size: VariablesSizes,
261
+ },
262
+ }
@@ -0,0 +1,4 @@
1
+ pub(crate) mod evaluators;
2
+ pub(crate) mod instructions;
3
+
4
+ pub(crate) type Program = Vec<instructions::Block>;
@@ -0,0 +1,42 @@
1
+ //! ![GQLite logo](https://gqlite.org/assets/images/logo-88x88.png) GQLite
2
+ //! ======================================================================
3
+ //!
4
+ //! Implementation of GQL (Graph Query Language), embeddable in applications.
5
+ //!
6
+ //! Add to your crate, using `cargo add gqlitedb`. Check-out [Connection]
7
+ //! for an example of use.
8
+
9
+ #![warn(missing_docs)]
10
+ #![allow(dead_code)]
11
+ #![deny(warnings)]
12
+
13
+ mod aggregators;
14
+ #[cfg(feature = "capi")]
15
+ mod capi;
16
+ mod compiler;
17
+ mod connection;
18
+ mod consts;
19
+ mod error;
20
+ mod functions;
21
+ mod graph;
22
+ mod interpreter;
23
+ mod parser;
24
+ mod prelude;
25
+ mod serialize_with;
26
+ mod store;
27
+ mod utils;
28
+ mod value;
29
+ mod value_table;
30
+
31
+ #[cfg(test)]
32
+ pub(crate) mod tests;
33
+
34
+ pub use {
35
+ connection::Connection,
36
+ error::{CompileTimeError, Error, RunTimeError, StoreError},
37
+ graph::{Edge, Node, Path},
38
+ value::{Value, ValueMap},
39
+ };
40
+
41
+ /// GQLite Result alias. Usable as a standard `Result<T, E>` or default to gqlite::Error with `Result<T>`
42
+ pub type Result<T, E = error::export::Error> = std::result::Result<T, E>;