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,132 +0,0 @@
|
|
1
|
-
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
2
|
-
#
|
3
|
-
# When uploading crates to the registry Cargo will automatically
|
4
|
-
# "normalize" Cargo.toml files for maximal compatibility
|
5
|
-
# with all versions of Cargo and also rewrite `path` dependencies
|
6
|
-
# to registry (e.g., crates.io) dependencies.
|
7
|
-
#
|
8
|
-
# If you are reading this file be aware that the original Cargo.toml
|
9
|
-
# will likely look very different (and much more reasonable).
|
10
|
-
# See Cargo.toml.orig for the original contents.
|
11
|
-
|
12
|
-
[package]
|
13
|
-
edition = "2021"
|
14
|
-
name = "gqlitedb"
|
15
|
-
version = "0.5.2"
|
16
|
-
build = false
|
17
|
-
autolib = false
|
18
|
-
autobins = false
|
19
|
-
autoexamples = false
|
20
|
-
autotests = false
|
21
|
-
autobenches = false
|
22
|
-
description = "GQLite is a Rust-language library, with a C interface, that implements a small, fast, self-contained, high-reliability, full-featured, Graph Query database engine."
|
23
|
-
homepage = "https://gqlite.org"
|
24
|
-
readme = "README.md"
|
25
|
-
license = "MIT"
|
26
|
-
repository = "https://gitlab.com/gqlite/gqlite"
|
27
|
-
|
28
|
-
[features]
|
29
|
-
_backtrace = []
|
30
|
-
_pg13 = ["pgrx/pg13"]
|
31
|
-
_pg14 = ["pgrx/pg14"]
|
32
|
-
_pg15 = ["pgrx/pg15"]
|
33
|
-
_pg16 = ["pgrx/pg16"]
|
34
|
-
_pg17 = ["pgrx/pg17"]
|
35
|
-
_pgql = ["dep:pgrx"]
|
36
|
-
capi = []
|
37
|
-
default = [
|
38
|
-
"redb",
|
39
|
-
"capi",
|
40
|
-
"sqlite",
|
41
|
-
]
|
42
|
-
redb = ["dep:redb"]
|
43
|
-
sqlite = [
|
44
|
-
"dep:rusqlite",
|
45
|
-
"dep:askama",
|
46
|
-
]
|
47
|
-
|
48
|
-
[lib]
|
49
|
-
name = "gqlitedb"
|
50
|
-
crate-type = [
|
51
|
-
"cdylib",
|
52
|
-
"lib",
|
53
|
-
]
|
54
|
-
path = "src/lib.rs"
|
55
|
-
|
56
|
-
[[bench]]
|
57
|
-
name = "pokec_divan"
|
58
|
-
path = "benches/pokec_divan.rs"
|
59
|
-
harness = false
|
60
|
-
|
61
|
-
[[bench]]
|
62
|
-
name = "pokec_iai"
|
63
|
-
path = "benches/pokec_iai.rs"
|
64
|
-
harness = false
|
65
|
-
|
66
|
-
[dependencies.askama]
|
67
|
-
version = "0.14"
|
68
|
-
optional = true
|
69
|
-
|
70
|
-
[dependencies.ccutils]
|
71
|
-
version = "0.3"
|
72
|
-
features = [
|
73
|
-
"sync",
|
74
|
-
"pool",
|
75
|
-
]
|
76
|
-
|
77
|
-
[dependencies.ciborium]
|
78
|
-
version = "0.2"
|
79
|
-
|
80
|
-
[dependencies.itertools]
|
81
|
-
version = "0.14"
|
82
|
-
|
83
|
-
[dependencies.pest]
|
84
|
-
version = "2"
|
85
|
-
|
86
|
-
[dependencies.pest_derive]
|
87
|
-
version = "2"
|
88
|
-
|
89
|
-
[dependencies.pgrx]
|
90
|
-
version = "0.15"
|
91
|
-
optional = true
|
92
|
-
|
93
|
-
[dependencies.rand]
|
94
|
-
version = "0.9"
|
95
|
-
|
96
|
-
[dependencies.redb]
|
97
|
-
version = "2"
|
98
|
-
optional = true
|
99
|
-
|
100
|
-
[dependencies.rusqlite]
|
101
|
-
version = "0.37"
|
102
|
-
features = [
|
103
|
-
"functions",
|
104
|
-
"uuid",
|
105
|
-
]
|
106
|
-
optional = true
|
107
|
-
|
108
|
-
[dependencies.serde]
|
109
|
-
version = "1"
|
110
|
-
|
111
|
-
[dependencies.serde_json]
|
112
|
-
version = "1"
|
113
|
-
|
114
|
-
[dependencies.thiserror]
|
115
|
-
version = "2"
|
116
|
-
|
117
|
-
[dependencies.uuid]
|
118
|
-
version = "1"
|
119
|
-
features = ["v4"]
|
120
|
-
|
121
|
-
[dev-dependencies.ccutils]
|
122
|
-
version = "0.3"
|
123
|
-
features = ["temporary"]
|
124
|
-
|
125
|
-
[dev-dependencies.divan]
|
126
|
-
version = "0.1"
|
127
|
-
|
128
|
-
[dev-dependencies.iai-callgrind]
|
129
|
-
version = "0.16"
|
130
|
-
|
131
|
-
[dev-dependencies.regex]
|
132
|
-
version = "1"
|
@@ -1,208 +0,0 @@
|
|
1
|
-
use crate::prelude::*;
|
2
|
-
use value::ValueTryIntoRef;
|
3
|
-
|
4
|
-
trait ConnectionTrait: Sync + Send
|
5
|
-
{
|
6
|
-
fn execute_query(&self, query: String, parameters: value::ValueMap) -> Result<value::Value>;
|
7
|
-
}
|
8
|
-
|
9
|
-
struct ConnectionImpl<TStore>
|
10
|
-
where
|
11
|
-
TStore: store::Store + Sync + Send,
|
12
|
-
{
|
13
|
-
store: TStore,
|
14
|
-
function_manager: functions::Manager,
|
15
|
-
}
|
16
|
-
|
17
|
-
impl<TStore> ConnectionTrait for ConnectionImpl<TStore>
|
18
|
-
where
|
19
|
-
TStore: store::Store + Sync + Send,
|
20
|
-
{
|
21
|
-
fn execute_query(&self, query: String, parameters: value::ValueMap) -> Result<value::Value>
|
22
|
-
{
|
23
|
-
let query_txt: String = query.into();
|
24
|
-
let queries = parser::parse(query_txt.as_str())?;
|
25
|
-
let mut results = Vec::<value::Value>::default();
|
26
|
-
for query in queries
|
27
|
-
{
|
28
|
-
let program = compiler::compile(&self.function_manager, query)?;
|
29
|
-
let v = interpreter::evaluators::eval_program(&self.store, &program, ¶meters)?;
|
30
|
-
if !v.is_null()
|
31
|
-
{
|
32
|
-
results.push(v);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
match results.len()
|
36
|
-
{
|
37
|
-
0 => Ok(value::Value::Null),
|
38
|
-
1 => Ok(results.into_iter().next().unwrap()),
|
39
|
-
_ =>
|
40
|
-
{
|
41
|
-
let mut map = value::ValueMap::new();
|
42
|
-
map.insert("type".into(), "results".into());
|
43
|
-
map.insert("results".into(), results.into());
|
44
|
-
Ok(map.into())
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
impl<TStore: store::Store> ConnectionImpl<TStore>
|
51
|
-
where
|
52
|
-
TStore: store::Store + Sync + Send,
|
53
|
-
{
|
54
|
-
fn boxed(self) -> Box<Self>
|
55
|
-
{
|
56
|
-
Box::new(self)
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
/// Connection is the interface to the database, and allow to execute new queries.
|
61
|
-
/// New connection are created with [Connection::open] and queried with [Connection::execute_query].
|
62
|
-
/// As shown in the example bellow:
|
63
|
-
///
|
64
|
-
/// ```rust
|
65
|
-
/// # use gqlitedb::{Connection, Value};
|
66
|
-
/// # fn example() -> gqlitedb::Result<()> {
|
67
|
-
/// let connection = Connection::open("filename.db", gqlitedb::map!("backend" => "redb"))?;
|
68
|
-
/// let value = connection.execute_query("MATCH (a) RETURN a", Default::default())?;
|
69
|
-
/// match value
|
70
|
-
/// {
|
71
|
-
/// Value::Array(arr) =>
|
72
|
-
/// {
|
73
|
-
/// arr.iter().for_each(|row| match row
|
74
|
-
/// {
|
75
|
-
/// Value::Array(arr) =>
|
76
|
-
/// {
|
77
|
-
/// println!("{:?}", arr);
|
78
|
-
/// }
|
79
|
-
/// _ =>
|
80
|
-
/// {
|
81
|
-
/// panic!("Unexpected: {}", row);
|
82
|
-
/// }
|
83
|
-
/// });
|
84
|
-
/// },
|
85
|
-
/// _ => {
|
86
|
-
/// panic!("Query result should be an array, got {}!", value);
|
87
|
-
/// }
|
88
|
-
/// }
|
89
|
-
/// # Ok(()) }
|
90
|
-
/// ```
|
91
|
-
|
92
|
-
pub struct Connection
|
93
|
-
{
|
94
|
-
connection: Box<dyn ConnectionTrait>,
|
95
|
-
}
|
96
|
-
|
97
|
-
ccutils::assert_impl_all!(Connection: Sync, Send);
|
98
|
-
|
99
|
-
impl Connection
|
100
|
-
{
|
101
|
-
/// Open a `path` that contains a `GQLite` database. The `options` parameter can
|
102
|
-
/// be used to select the backend, and configure the backend.
|
103
|
-
///
|
104
|
-
/// Supported parameters:
|
105
|
-
/// - `backend` can be `redb` or `sqlite`
|
106
|
-
///
|
107
|
-
/// If the `backend` is not specified, the `open` function will attempt to guess it
|
108
|
-
/// for existing databases. For new database, depending on availability, it will
|
109
|
-
/// create a `sqlite` database, or a `redb` database.
|
110
|
-
///
|
111
|
-
/// Example of use:
|
112
|
-
///
|
113
|
-
/// ```rust
|
114
|
-
/// # use gqlitedb::Connection;
|
115
|
-
/// # fn example() -> gqlitedb::Result<()> {
|
116
|
-
/// let connection = Connection::open("filename.db", gqlitedb::map!("backend" => "redb"))?;
|
117
|
-
/// # Ok(()) }
|
118
|
-
/// ```
|
119
|
-
#[cfg(any(feature = "redb", feature = "sqlite"))]
|
120
|
-
pub fn open<P: AsRef<std::path::Path>>(path: P, options: value::ValueMap) -> Result<Connection>
|
121
|
-
{
|
122
|
-
if let Some(backend) = options.get("backend")
|
123
|
-
{
|
124
|
-
let backend: &String = backend.try_into_ref()?;
|
125
|
-
match backend.as_str()
|
126
|
-
{
|
127
|
-
"sqlite" => Self::open_sqlite(path),
|
128
|
-
"redb" => Self::open_redb(path),
|
129
|
-
_ => Err(
|
130
|
-
StoreError::UnknownBackend {
|
131
|
-
backend: backend.to_owned(),
|
132
|
-
}
|
133
|
-
.into(),
|
134
|
-
),
|
135
|
-
}
|
136
|
-
}
|
137
|
-
else
|
138
|
-
{
|
139
|
-
Self::open_sqlite(path.as_ref().to_owned()).or_else(|sq_e| {
|
140
|
-
Self::open_redb(path).map_err(|rb_e| {
|
141
|
-
StoreError::OpeningError {
|
142
|
-
errors: error::vec_to_error::<ErrorType>(&vec![sq_e, rb_e]),
|
143
|
-
}
|
144
|
-
.into()
|
145
|
-
})
|
146
|
-
})
|
147
|
-
}
|
148
|
-
}
|
149
|
-
#[cfg(feature = "sqlite")]
|
150
|
-
fn open_sqlite<P: AsRef<std::path::Path>>(path: P) -> Result<Connection>
|
151
|
-
{
|
152
|
-
Ok(Connection {
|
153
|
-
connection: ConnectionImpl {
|
154
|
-
store: store::sqlite::Store::new(path)?,
|
155
|
-
function_manager: functions::Manager::new(),
|
156
|
-
}
|
157
|
-
.boxed(),
|
158
|
-
})
|
159
|
-
}
|
160
|
-
#[cfg(not(feature = "sqlite"))]
|
161
|
-
fn open_sqlite<P: AsRef<std::path::Path>>(_: P) -> Result<Connection>
|
162
|
-
{
|
163
|
-
Err(error::ConnectionError::UnavailableBackend { backend: "sqlite" }.into())
|
164
|
-
}
|
165
|
-
#[cfg(feature = "redb")]
|
166
|
-
fn open_redb<P: AsRef<std::path::Path>>(path: P) -> Result<Connection>
|
167
|
-
{
|
168
|
-
Ok(Connection {
|
169
|
-
connection: ConnectionImpl {
|
170
|
-
store: store::redb::Store::new(path)?,
|
171
|
-
function_manager: functions::Manager::new(),
|
172
|
-
}
|
173
|
-
.boxed(),
|
174
|
-
})
|
175
|
-
}
|
176
|
-
#[cfg(not(feature = "redb"))]
|
177
|
-
fn open_redb<P: AsRef<std::path::Path>>(_: P) -> Result<Connection>
|
178
|
-
{
|
179
|
-
Err(error::StoreError::UnavailableBackend { backend: "redb" }.into())
|
180
|
-
}
|
181
|
-
#[cfg(feature = "_pgql")]
|
182
|
-
pub fn create() -> Result<Connection>
|
183
|
-
{
|
184
|
-
Ok(Connection {
|
185
|
-
store: store::Store::new()?,
|
186
|
-
})
|
187
|
-
}
|
188
|
-
/// Execute the `query` (using OpenCypher), given the query `parameters` (sometimes
|
189
|
-
/// also referred as binding).
|
190
|
-
///
|
191
|
-
/// Example:
|
192
|
-
///
|
193
|
-
/// ```rust
|
194
|
-
/// # use gqlitedb::{Connection, Value};
|
195
|
-
/// # fn example() -> gqlitedb::Result<()> {
|
196
|
-
/// # let connection = gqlitedb::Connection::open("filename.db", gqlitedb::map!("backend" => "redb"))?;
|
197
|
-
/// let result = connection.execute_query("MATCH (a { name: $name }) RETURN a", gqlitedb::map!("name" => "Joe"))?;
|
198
|
-
/// # Ok(()) }
|
199
|
-
/// ```
|
200
|
-
pub fn execute_query(
|
201
|
-
&self,
|
202
|
-
query: impl Into<String>,
|
203
|
-
parameters: value::ValueMap,
|
204
|
-
) -> Result<value::Value>
|
205
|
-
{
|
206
|
-
self.connection.execute_query(query.into(), parameters)
|
207
|
-
}
|
208
|
-
}
|
@@ -1,48 +0,0 @@
|
|
1
|
-
use super::ExpressionType;
|
2
|
-
use crate::prelude::*;
|
3
|
-
|
4
|
-
#[derive(Debug, Default)]
|
5
|
-
pub(super) struct Length {}
|
6
|
-
|
7
|
-
impl super::FunctionTrait for Length
|
8
|
-
{
|
9
|
-
fn call(&self, arguments: Vec<value::Value>) -> crate::Result<value::Value>
|
10
|
-
{
|
11
|
-
let container = arguments
|
12
|
-
.first()
|
13
|
-
.ok_or_else(|| RunTimeError::InvalidNumberOfArguments {
|
14
|
-
function_name: "length",
|
15
|
-
got: arguments.len(),
|
16
|
-
expected: 1,
|
17
|
-
})?;
|
18
|
-
|
19
|
-
match container
|
20
|
-
{
|
21
|
-
value::Value::Array(arr) => Ok((arr.len() as i64).into()),
|
22
|
-
value::Value::Map(obj) => Ok((obj.len() as i64).into()),
|
23
|
-
value::Value::Path(..) => Ok(1.into()),
|
24
|
-
_ =>
|
25
|
-
{
|
26
|
-
return Err(
|
27
|
-
RunTimeError::InvalidArgument {
|
28
|
-
function_name: "length",
|
29
|
-
index: 0,
|
30
|
-
expected_type: "array or map",
|
31
|
-
value: format!("{:?}", container),
|
32
|
-
}
|
33
|
-
.into(),
|
34
|
-
)
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
fn validate_arguments(&self, _: Vec<ExpressionType>) -> crate::Result<ExpressionType>
|
39
|
-
{
|
40
|
-
Ok(ExpressionType::Variant)
|
41
|
-
}
|
42
|
-
fn is_deterministic(&self) -> bool
|
43
|
-
{
|
44
|
-
true
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
super::declare_function!(length, Length, custom_trait);
|