gqlite 1.5.0 → 1.5.1
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 +2 -2
- data/ext/gqlitedb/Cargo.toml +1 -0
- data/ext/gqlitedb/src/capi.rs +19 -23
- data/ext/gqlitedb/src/compiler/variables_manager.rs +7 -9
- data/ext/gqlitedb/src/compiler.rs +2 -3
- data/ext/gqlitedb/src/connection.rs +2 -0
- data/ext/gqlitedb/src/functions/common.rs +27 -0
- data/ext/gqlitedb/src/functions/containers.rs +2 -46
- data/ext/gqlitedb/src/functions/edge.rs +1 -1
- data/ext/gqlitedb/src/functions/math.rs +80 -13
- data/ext/gqlitedb/src/functions/node.rs +1 -1
- data/ext/gqlitedb/src/functions/scalar.rs +47 -4
- data/ext/gqlitedb/src/functions/string.rs +123 -1
- data/ext/gqlitedb/src/functions.rs +148 -27
- data/ext/gqlitedb/src/parser/gql.pest +1 -1
- data/ext/gqlitedb/src/store/postgres.rs +10 -12
- data/ext/gqlitedb/src/store/sqlite.rs +8 -10
- data/ext/gqlitedb/src/store.rs +17 -26
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34702a81803ce382efb13f4206de1f1ba73329cd0a3ffe52238d32eb979a427a
|
|
4
|
+
data.tar.gz: e9ccb531863f44072f0d6e58102296b32c54ad0f071772da755d031836d44b78
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4cdf5b62762da1c470888c26d950e39e1843c91825f96b0a5cf4e6d39c4a26e981f16a6cef13153c21781996189569895310b758469d35777f0f71c56b7748ee
|
|
7
|
+
data.tar.gz: '07697d27aea70038327f849f70231568824cd5a2b6a539eb4567476cf9def21f01469003050ec14ce5626e4b603dfdf5db79b9ab631267dc500672ab21c4f8ab'
|
data/ext/Cargo.toml
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[workspace]
|
|
2
|
-
resolver = "
|
|
2
|
+
resolver = "3"
|
|
3
3
|
members = ["gqliterb", "gqlitedb", "graphcore"]
|
|
4
4
|
|
|
5
5
|
[workspace.package]
|
|
6
6
|
version = "0.8.0"
|
|
7
|
-
edition = "
|
|
7
|
+
edition = "2024"
|
|
8
8
|
license = "MIT"
|
|
9
9
|
homepage = "https://gqlite.org"
|
|
10
10
|
repository = "https://gitlab.com/gqlite/gqlite"
|
data/ext/gqlitedb/Cargo.toml
CHANGED
data/ext/gqlitedb/src/capi.rs
CHANGED
|
@@ -65,7 +65,7 @@ pub struct GqliteValueT
|
|
|
65
65
|
value: crate::value::Value,
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
#[no_mangle]
|
|
68
|
+
#[unsafe(no_mangle)]
|
|
69
69
|
pub extern "C" fn gqlite_api_context_create() -> *mut GqliteApiContextT
|
|
70
70
|
{
|
|
71
71
|
Box::into_raw(Box::new(GqliteApiContextT {
|
|
@@ -74,7 +74,7 @@ pub extern "C" fn gqlite_api_context_create() -> *mut GqliteApiContextT
|
|
|
74
74
|
}))
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
#[no_mangle]
|
|
77
|
+
#[unsafe(no_mangle)]
|
|
78
78
|
pub extern "C" fn gqlite_api_context_destroy(context: *mut GqliteApiContextT)
|
|
79
79
|
{
|
|
80
80
|
unsafe {
|
|
@@ -82,7 +82,7 @@ pub extern "C" fn gqlite_api_context_destroy(context: *mut GqliteApiContextT)
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
#[no_mangle]
|
|
85
|
+
#[unsafe(no_mangle)]
|
|
86
86
|
pub extern "C" fn gqlite_api_context_get_message(
|
|
87
87
|
context: *mut GqliteApiContextT,
|
|
88
88
|
) -> *const std::ffi::c_char
|
|
@@ -90,13 +90,13 @@ pub extern "C" fn gqlite_api_context_get_message(
|
|
|
90
90
|
unsafe { (*context).string.as_ptr() }
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
#[no_mangle]
|
|
93
|
+
#[unsafe(no_mangle)]
|
|
94
94
|
pub extern "C" fn gqlite_api_context_has_error(context: *mut GqliteApiContextT) -> bool
|
|
95
95
|
{
|
|
96
96
|
unsafe { (*context).has_error }
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
#[no_mangle]
|
|
99
|
+
#[unsafe(no_mangle)]
|
|
100
100
|
pub extern "C" fn gqlite_api_context_clear_error(context: *mut GqliteApiContextT)
|
|
101
101
|
{
|
|
102
102
|
let mut context = unsafe { Box::from_raw(context) };
|
|
@@ -104,7 +104,7 @@ pub extern "C" fn gqlite_api_context_clear_error(context: *mut GqliteApiContextT
|
|
|
104
104
|
let _ = Box::into_raw(context);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
#[no_mangle]
|
|
107
|
+
#[unsafe(no_mangle)]
|
|
108
108
|
pub extern "C" fn gqlite_connection_create_from_file(
|
|
109
109
|
context: *mut GqliteApiContextT,
|
|
110
110
|
filename: *const std::ffi::c_char,
|
|
@@ -116,22 +116,20 @@ pub extern "C" fn gqlite_connection_create_from_file(
|
|
|
116
116
|
let path = unsafe { std::ffi::CStr::from_ptr(filename) };
|
|
117
117
|
|
|
118
118
|
if let Ok(path) = handle_error(context, path.to_str())
|
|
119
|
-
|
|
120
|
-
if let Ok(c) = handle_error(
|
|
119
|
+
&& let Ok(c) = handle_error(
|
|
121
120
|
context,
|
|
122
121
|
crate::Connection::builder()
|
|
123
122
|
.options(options.into_map())
|
|
124
123
|
.path(path)
|
|
125
124
|
.create(),
|
|
126
125
|
)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
126
|
+
{
|
|
127
|
+
return Box::into_raw(Box::new(GqliteConnectionT { connection: c }));
|
|
130
128
|
}
|
|
131
129
|
std::ptr::null::<GqliteConnectionT>() as *mut GqliteConnectionT
|
|
132
130
|
}
|
|
133
131
|
|
|
134
|
-
#[no_mangle]
|
|
132
|
+
#[unsafe(no_mangle)]
|
|
135
133
|
pub extern "C" fn gqlite_connection_create(
|
|
136
134
|
context: *mut GqliteApiContextT,
|
|
137
135
|
options: *mut GqliteValueT,
|
|
@@ -147,7 +145,7 @@ pub extern "C" fn gqlite_connection_create(
|
|
|
147
145
|
std::ptr::null::<GqliteConnectionT>() as *mut GqliteConnectionT
|
|
148
146
|
}
|
|
149
147
|
|
|
150
|
-
#[no_mangle]
|
|
148
|
+
#[unsafe(no_mangle)]
|
|
151
149
|
pub extern "C" fn gqlite_connection_destroy(
|
|
152
150
|
_context: *mut GqliteApiContextT,
|
|
153
151
|
connection: *mut GqliteConnectionT,
|
|
@@ -158,7 +156,7 @@ pub extern "C" fn gqlite_connection_destroy(
|
|
|
158
156
|
}
|
|
159
157
|
}
|
|
160
158
|
|
|
161
|
-
#[no_mangle]
|
|
159
|
+
#[unsafe(no_mangle)]
|
|
162
160
|
pub extern "C" fn gqlite_connection_query(
|
|
163
161
|
context: *mut GqliteApiContextT,
|
|
164
162
|
connection: *mut GqliteConnectionT,
|
|
@@ -185,7 +183,7 @@ pub extern "C" fn gqlite_connection_query(
|
|
|
185
183
|
std::ptr::null::<GqliteValueT>() as *mut GqliteValueT
|
|
186
184
|
}
|
|
187
185
|
|
|
188
|
-
#[no_mangle]
|
|
186
|
+
#[unsafe(no_mangle)]
|
|
189
187
|
pub extern "C" fn gqlite_value_create(context: *mut GqliteApiContextT) -> *mut GqliteValueT
|
|
190
188
|
{
|
|
191
189
|
check_error(context);
|
|
@@ -194,7 +192,7 @@ pub extern "C" fn gqlite_value_create(context: *mut GqliteApiContextT) -> *mut G
|
|
|
194
192
|
}))
|
|
195
193
|
}
|
|
196
194
|
|
|
197
|
-
#[no_mangle]
|
|
195
|
+
#[unsafe(no_mangle)]
|
|
198
196
|
pub extern "C" fn gqlite_value_destroy(context: *mut GqliteApiContextT, value: *mut GqliteValueT)
|
|
199
197
|
{
|
|
200
198
|
check_error(context);
|
|
@@ -203,7 +201,7 @@ pub extern "C" fn gqlite_value_destroy(context: *mut GqliteApiContextT, value: *
|
|
|
203
201
|
}
|
|
204
202
|
}
|
|
205
203
|
|
|
206
|
-
#[no_mangle]
|
|
204
|
+
#[unsafe(no_mangle)]
|
|
207
205
|
pub extern "C" fn gqlite_value_to_json(
|
|
208
206
|
context: *mut GqliteApiContextT,
|
|
209
207
|
value: *mut GqliteValueT,
|
|
@@ -227,7 +225,7 @@ pub extern "C" fn gqlite_value_to_json(
|
|
|
227
225
|
std::ptr::null()
|
|
228
226
|
}
|
|
229
227
|
|
|
230
|
-
#[no_mangle]
|
|
228
|
+
#[unsafe(no_mangle)]
|
|
231
229
|
pub extern "C" fn gqlite_value_from_json(
|
|
232
230
|
context: *mut GqliteApiContextT,
|
|
233
231
|
json: *const std::ffi::c_char,
|
|
@@ -237,16 +235,14 @@ pub extern "C" fn gqlite_value_from_json(
|
|
|
237
235
|
|
|
238
236
|
let json = unsafe { std::ffi::CStr::from_ptr(json) };
|
|
239
237
|
if let Ok(json) = handle_error(context, json.to_str())
|
|
238
|
+
&& let Ok(v) = handle_error(context, serde_json::from_str::<crate::value::Value>(json))
|
|
240
239
|
{
|
|
241
|
-
|
|
242
|
-
{
|
|
243
|
-
return Box::into_raw(Box::new(GqliteValueT { value: v }));
|
|
244
|
-
}
|
|
240
|
+
return Box::into_raw(Box::new(GqliteValueT { value: v }));
|
|
245
241
|
}
|
|
246
242
|
std::ptr::null::<GqliteValueT>() as *mut GqliteValueT
|
|
247
243
|
}
|
|
248
244
|
|
|
249
|
-
#[no_mangle]
|
|
245
|
+
#[unsafe(no_mangle)]
|
|
250
246
|
pub extern "C" fn gqlite_value_is_valid(
|
|
251
247
|
context: *mut GqliteApiContextT,
|
|
252
248
|
value: *mut GqliteValueT,
|
|
@@ -572,16 +572,14 @@ impl VariablesManager
|
|
|
572
572
|
for pattern in create.patterns.iter()
|
|
573
573
|
{
|
|
574
574
|
if let ast::Pattern::Node(n) = &pattern
|
|
575
|
+
&& self.has_variable(&n.variable)
|
|
575
576
|
{
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
.into(),
|
|
583
|
-
);
|
|
584
|
-
}
|
|
577
|
+
return Err(
|
|
578
|
+
CompileTimeError::VariableAlreadyBound {
|
|
579
|
+
name: n.variable.clone().unwrap().name().clone(),
|
|
580
|
+
}
|
|
581
|
+
.into(),
|
|
582
|
+
);
|
|
585
583
|
}
|
|
586
584
|
self.analyse_pattern(pattern, true)?;
|
|
587
585
|
}
|
|
@@ -938,7 +938,7 @@ pub(crate) fn compile(
|
|
|
938
938
|
.map(|stmt| {
|
|
939
939
|
compiler.temporary_variables = 0;
|
|
940
940
|
compiler.variables_manager.analyse(stmt)?;
|
|
941
|
-
|
|
941
|
+
match stmt
|
|
942
942
|
{
|
|
943
943
|
ast::Statement::CreateGraph(create_graph) => Ok(Block::CreateGraph {
|
|
944
944
|
name: create_graph.name.to_owned(),
|
|
@@ -1107,8 +1107,7 @@ pub(crate) fn compile(
|
|
|
1107
1107
|
.collect::<Result<_>>()?,
|
|
1108
1108
|
variables_size: compiler.variables_size(),
|
|
1109
1109
|
}),
|
|
1110
|
-
}
|
|
1111
|
-
inst
|
|
1110
|
+
}
|
|
1112
1111
|
})
|
|
1113
1112
|
.scan(&mut statements_err, |err, gp| {
|
|
1114
1113
|
gp.map_err(|e| **err = Err(e)).ok()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
use super::FResult;
|
|
2
|
+
use crate::prelude::*;
|
|
3
|
+
|
|
4
|
+
#[derive(Debug, Default)]
|
|
5
|
+
pub(super) struct Size {}
|
|
6
|
+
|
|
7
|
+
impl Size
|
|
8
|
+
{
|
|
9
|
+
fn call_impl(value: value::Value) -> FResult<i64>
|
|
10
|
+
{
|
|
11
|
+
match value
|
|
12
|
+
{
|
|
13
|
+
value::Value::String(str) => Ok(str.len() as i64),
|
|
14
|
+
value::Value::Array(arr) => Ok(arr.len() as i64),
|
|
15
|
+
value::Value::Map(obj) => Ok(obj.len() as i64),
|
|
16
|
+
value::Value::Path(..) => Ok(1.into()),
|
|
17
|
+
_ => Err(RunTimeError::InvalidArgument {
|
|
18
|
+
function_name: "size",
|
|
19
|
+
index: 0,
|
|
20
|
+
expected_type: "array, map or string",
|
|
21
|
+
value: format!("{:?}", value),
|
|
22
|
+
}),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
super::declare_function!(size, Size, call_impl(graphcore::Value) -> i64, null_handling(null_returns_null));
|
|
@@ -21,7 +21,7 @@ super::declare_function!(
|
|
|
21
21
|
head,
|
|
22
22
|
Head,
|
|
23
23
|
call_impl(Vec<crate::value::Value>) -> crate::value::Value,
|
|
24
|
-
|
|
24
|
+
null_handling(null_returns_null)
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
#[derive(Debug, Default)]
|
|
@@ -49,7 +49,7 @@ impl Keys
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
super::declare_function!(keys, Keys, call_impl(crate::value::Value) -> Vec<crate::value::Value>, validate_args(ExpressionType::Map | ExpressionType::Node | ExpressionType::Edge | ExpressionType::Null));
|
|
52
|
+
super::declare_function!(keys, Keys, call_impl(crate::value::Value) -> Vec<crate::value::Value>, null_handling(null_returns_null), validate_args(ExpressionType::Map | ExpressionType::Node | ExpressionType::Edge | ExpressionType::Null));
|
|
53
53
|
|
|
54
54
|
#[derive(Debug, Default)]
|
|
55
55
|
pub(super) struct Range {}
|
|
@@ -63,47 +63,3 @@ impl Range
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
super::declare_function!(range, Range, call_impl(i64, i64) -> Vec<i64>);
|
|
66
|
-
|
|
67
|
-
#[derive(Debug, Default)]
|
|
68
|
-
pub(super) struct Size {}
|
|
69
|
-
|
|
70
|
-
impl super::FunctionTrait for Size
|
|
71
|
-
{
|
|
72
|
-
fn call(&self, arguments: Vec<value::Value>) -> Result<value::Value>
|
|
73
|
-
{
|
|
74
|
-
let container = arguments
|
|
75
|
-
.first()
|
|
76
|
-
.ok_or(RunTimeError::InvalidNumberOfArguments {
|
|
77
|
-
function_name: "size",
|
|
78
|
-
got: arguments.len(),
|
|
79
|
-
expected: 1,
|
|
80
|
-
})?;
|
|
81
|
-
|
|
82
|
-
match container
|
|
83
|
-
{
|
|
84
|
-
value::Value::Null => Ok(value::Value::Null),
|
|
85
|
-
value::Value::Array(arr) => Ok((arr.len() as i64).into()),
|
|
86
|
-
value::Value::Map(obj) => Ok((obj.len() as i64).into()),
|
|
87
|
-
value::Value::Path(..) => Ok(1.into()),
|
|
88
|
-
_ => Err(
|
|
89
|
-
RunTimeError::InvalidArgument {
|
|
90
|
-
function_name: "size",
|
|
91
|
-
index: 0,
|
|
92
|
-
expected_type: "array or map",
|
|
93
|
-
value: format!("{:?}", container),
|
|
94
|
-
}
|
|
95
|
-
.into(),
|
|
96
|
-
),
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
fn validate_arguments(&self, _: Vec<ExpressionType>) -> Result<ExpressionType>
|
|
100
|
-
{
|
|
101
|
-
Ok(ExpressionType::Variant)
|
|
102
|
-
}
|
|
103
|
-
fn is_deterministic(&self) -> bool
|
|
104
|
-
{
|
|
105
|
-
true
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
super::declare_function!(size, Size, custom_trait);
|
|
@@ -4,6 +4,39 @@ use crate::prelude::*;
|
|
|
4
4
|
|
|
5
5
|
use super::FResult;
|
|
6
6
|
|
|
7
|
+
trait Extra
|
|
8
|
+
{
|
|
9
|
+
fn cot(self) -> Self;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
impl Extra for f64
|
|
13
|
+
{
|
|
14
|
+
fn cot(self) -> Self
|
|
15
|
+
{
|
|
16
|
+
self.cos() / self.sin()
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
macro_rules! declare_constant {
|
|
21
|
+
($name: ident, $class_name: ident, $rust_const: ident) => {
|
|
22
|
+
#[derive(Debug, Default)]
|
|
23
|
+
pub(super) struct $class_name {}
|
|
24
|
+
|
|
25
|
+
impl $class_name
|
|
26
|
+
{
|
|
27
|
+
fn call_impl() -> FResult<f64>
|
|
28
|
+
{
|
|
29
|
+
Ok(std::f64::consts::$rust_const)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
super::declare_function!($name, $class_name, call_impl() -> f64);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare_constant!(pi, Pi, PI);
|
|
38
|
+
declare_constant!(e, E, E);
|
|
39
|
+
|
|
7
40
|
#[derive(Debug, Default)]
|
|
8
41
|
pub(super) struct Rand {}
|
|
9
42
|
|
|
@@ -17,28 +50,62 @@ impl Rand
|
|
|
17
50
|
|
|
18
51
|
super::declare_function!(rand, Rand, call_impl() -> Vec<f64>);
|
|
19
52
|
|
|
53
|
+
macro_rules! define_f64_function {
|
|
54
|
+
($name: ident, $class_name: ident, $rust_func: ident $(, $arg0: expr)*) => {
|
|
55
|
+
#[derive(Debug, Default)]
|
|
56
|
+
pub(super) struct $class_name {}
|
|
57
|
+
|
|
58
|
+
impl $class_name
|
|
59
|
+
{
|
|
60
|
+
fn call_impl(value: f64) -> FResult<f64>
|
|
61
|
+
{
|
|
62
|
+
Ok(value.$rust_func($($arg0)*))
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
super::declare_function!($name, $class_name, call_impl(f64) -> f64);
|
|
67
|
+
|
|
68
|
+
};
|
|
69
|
+
($name: ident, $class_name: ident) => {
|
|
70
|
+
define_f64_function!($name, $class_name, $name);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
define_f64_function!(exp, Exp);
|
|
75
|
+
define_f64_function!(log, Log, ln);
|
|
76
|
+
define_f64_function!(log10, Log10, log10);
|
|
77
|
+
define_f64_function!(sin, Sin);
|
|
78
|
+
define_f64_function!(cos, Cos);
|
|
79
|
+
define_f64_function!(tan, Tan);
|
|
80
|
+
define_f64_function!(cot, Cot, cot);
|
|
81
|
+
define_f64_function!(acos, Acos);
|
|
82
|
+
define_f64_function!(asin, Asin);
|
|
83
|
+
define_f64_function!(atan, Atan);
|
|
84
|
+
define_f64_function!(floor, Floor);
|
|
85
|
+
define_f64_function!(ceil, Ceil);
|
|
86
|
+
define_f64_function!(degrees, Degrees, to_degrees);
|
|
87
|
+
define_f64_function!(radians, Radians, to_radians);
|
|
88
|
+
|
|
20
89
|
#[derive(Debug, Default)]
|
|
21
|
-
pub(super) struct
|
|
90
|
+
pub(super) struct Atan2 {}
|
|
22
91
|
|
|
23
|
-
impl
|
|
92
|
+
impl Atan2
|
|
24
93
|
{
|
|
25
|
-
fn call_impl(
|
|
94
|
+
fn call_impl(x: f64, y: f64) -> FResult<f64>
|
|
26
95
|
{
|
|
27
|
-
Ok(
|
|
96
|
+
Ok(x.atan2(y))
|
|
28
97
|
}
|
|
29
98
|
}
|
|
30
99
|
|
|
31
|
-
super::declare_function!(
|
|
100
|
+
super::declare_function!(atan2, Atan2, call_impl(f64, f64) -> f64);
|
|
32
101
|
|
|
33
|
-
#[
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
impl Floor
|
|
102
|
+
#[cfg(test)]
|
|
103
|
+
mod test
|
|
37
104
|
{
|
|
38
|
-
|
|
105
|
+
use crate::functions::math::Extra as _;
|
|
106
|
+
#[test]
|
|
107
|
+
fn test_cot()
|
|
39
108
|
{
|
|
40
|
-
|
|
109
|
+
assert_eq!(0.5_f64.cot(), 1.830487721712452);
|
|
41
110
|
}
|
|
42
111
|
}
|
|
43
|
-
|
|
44
|
-
super::declare_function!(floor, Floor, call_impl(f64) -> f64);
|
|
@@ -2,6 +2,34 @@ use crate::prelude::*;
|
|
|
2
2
|
|
|
3
3
|
use super::{ExpressionType, FResult, FunctionTypeTrait};
|
|
4
4
|
|
|
5
|
+
#[derive(Debug, Default)]
|
|
6
|
+
pub(super) struct Abs {}
|
|
7
|
+
|
|
8
|
+
impl Abs
|
|
9
|
+
{
|
|
10
|
+
fn call_impl(value: value::Value) -> FResult<value::Value>
|
|
11
|
+
{
|
|
12
|
+
match value
|
|
13
|
+
{
|
|
14
|
+
value::Value::Integer(i) => Ok(i.abs().into()),
|
|
15
|
+
value::Value::Float(f) => Ok(f.abs().into()),
|
|
16
|
+
o => Err(RunTimeError::InvalidArgument {
|
|
17
|
+
function_name: "abs",
|
|
18
|
+
index: 0,
|
|
19
|
+
expected_type: "integer or float",
|
|
20
|
+
value: format!("{:?}", o),
|
|
21
|
+
}),
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
super::declare_function!(
|
|
27
|
+
abs, Abs,
|
|
28
|
+
call_impl(value::Value) -> value::Value,
|
|
29
|
+
null_handling(null_returns_null),
|
|
30
|
+
validate_args(ExpressionType::Integer | ExpressionType::Float)
|
|
31
|
+
);
|
|
32
|
+
|
|
5
33
|
#[derive(Debug, Default)]
|
|
6
34
|
pub(super) struct Coalesce {}
|
|
7
35
|
|
|
@@ -82,7 +110,12 @@ impl ToBoolean
|
|
|
82
110
|
}
|
|
83
111
|
}
|
|
84
112
|
|
|
85
|
-
super::declare_function!(
|
|
113
|
+
super::declare_function!(
|
|
114
|
+
toboolean, ToBoolean,
|
|
115
|
+
call_impl(crate::value::Value) -> bool,
|
|
116
|
+
null_handling(null_returns_null),
|
|
117
|
+
validate_args(ExpressionType::Boolean | ExpressionType::Integer | ExpressionType::Float | ExpressionType::String)
|
|
118
|
+
);
|
|
86
119
|
|
|
87
120
|
#[derive(Debug, Default)]
|
|
88
121
|
pub(super) struct ToFloat {}
|
|
@@ -110,7 +143,12 @@ impl ToFloat
|
|
|
110
143
|
}
|
|
111
144
|
}
|
|
112
145
|
|
|
113
|
-
super::declare_function!(
|
|
146
|
+
super::declare_function!(
|
|
147
|
+
tofloat, ToFloat,
|
|
148
|
+
call_impl(crate::value::Value) -> f64,
|
|
149
|
+
null_handling(null_returns_null),
|
|
150
|
+
validate_args(ExpressionType::Boolean | ExpressionType::Integer | ExpressionType::Float | ExpressionType::String)
|
|
151
|
+
);
|
|
114
152
|
|
|
115
153
|
#[derive(Debug, Default)]
|
|
116
154
|
pub(super) struct ToInteger {}
|
|
@@ -138,7 +176,12 @@ impl ToInteger
|
|
|
138
176
|
}
|
|
139
177
|
}
|
|
140
178
|
|
|
141
|
-
super::declare_function!(
|
|
179
|
+
super::declare_function!(
|
|
180
|
+
tointeger, ToInteger,
|
|
181
|
+
call_impl(crate::value::Value) -> i64,
|
|
182
|
+
null_handling(null_returns_null),
|
|
183
|
+
validate_args(ExpressionType::Boolean | ExpressionType::Integer | ExpressionType::Float | ExpressionType::String)
|
|
184
|
+
);
|
|
142
185
|
|
|
143
186
|
#[derive(Debug, Default)]
|
|
144
187
|
pub(super) struct Properties {}
|
|
@@ -162,4 +205,4 @@ impl Properties
|
|
|
162
205
|
}
|
|
163
206
|
}
|
|
164
207
|
|
|
165
|
-
super::declare_function!(properties, Properties, call_impl(crate::value::Value) -> value::ValueMap, validate_args(ExpressionType::Map | ExpressionType::Node | ExpressionType::Edge | ExpressionType::Null));
|
|
208
|
+
super::declare_function!(properties, Properties, call_impl(crate::value::Value) -> value::ValueMap, null_handling(null_returns_null), validate_args(ExpressionType::Map | ExpressionType::Node | ExpressionType::Edge | ExpressionType::Null));
|
|
@@ -2,6 +2,123 @@ use crate::prelude::*;
|
|
|
2
2
|
|
|
3
3
|
use super::{ExpressionType, FResult, FunctionTypeTrait};
|
|
4
4
|
|
|
5
|
+
#[derive(Debug, Default)]
|
|
6
|
+
pub(super) struct ToLower {}
|
|
7
|
+
|
|
8
|
+
impl ToLower
|
|
9
|
+
{
|
|
10
|
+
fn call_impl(string: String) -> FResult<String>
|
|
11
|
+
{
|
|
12
|
+
Ok(string.to_lowercase())
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
super::declare_function!(tolower, ToLower, call_impl(String) -> String, null_handling(null_returns_null));
|
|
17
|
+
|
|
18
|
+
#[derive(Debug, Default)]
|
|
19
|
+
pub(super) struct ToUpper {}
|
|
20
|
+
|
|
21
|
+
impl ToUpper
|
|
22
|
+
{
|
|
23
|
+
fn call_impl(string: String) -> FResult<String>
|
|
24
|
+
{
|
|
25
|
+
Ok(string.to_uppercase())
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
super::declare_function!(toupper, ToUpper, call_impl(String) -> String, null_handling(null_returns_null));
|
|
30
|
+
|
|
31
|
+
#[derive(Debug, Default)]
|
|
32
|
+
pub(super) struct LTrim {}
|
|
33
|
+
|
|
34
|
+
impl LTrim
|
|
35
|
+
{
|
|
36
|
+
fn call_impl(string: String) -> FResult<String>
|
|
37
|
+
{
|
|
38
|
+
Ok(string.trim_start().to_string())
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
super::declare_function!(ltrim, LTrim, call_impl(String) -> String, null_handling(null_returns_null));
|
|
43
|
+
|
|
44
|
+
#[derive(Debug, Default)]
|
|
45
|
+
pub(super) struct RTrim {}
|
|
46
|
+
|
|
47
|
+
impl RTrim
|
|
48
|
+
{
|
|
49
|
+
fn call_impl(string: String) -> FResult<String>
|
|
50
|
+
{
|
|
51
|
+
Ok(string.trim_end().to_string())
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
super::declare_function!(rtrim, RTrim, call_impl(String) -> String, null_handling(null_returns_null));
|
|
56
|
+
|
|
57
|
+
#[derive(Debug, Default)]
|
|
58
|
+
pub(super) struct Trim {}
|
|
59
|
+
|
|
60
|
+
impl Trim
|
|
61
|
+
{
|
|
62
|
+
fn call_impl(string: String) -> FResult<String>
|
|
63
|
+
{
|
|
64
|
+
Ok(string.trim().to_string())
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
super::declare_function!(trim, Trim, call_impl(String) -> String, null_handling(null_returns_null));
|
|
69
|
+
|
|
70
|
+
#[derive(Debug, Default)]
|
|
71
|
+
pub(super) struct Reverse {}
|
|
72
|
+
|
|
73
|
+
impl Reverse
|
|
74
|
+
{
|
|
75
|
+
fn call_impl(string: String) -> FResult<String>
|
|
76
|
+
{
|
|
77
|
+
Ok(string.chars().rev().collect())
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
super::declare_function!(reverse, Reverse, call_impl(String) -> String, null_handling(null_returns_null));
|
|
82
|
+
|
|
83
|
+
#[derive(Debug, Default)]
|
|
84
|
+
pub(super) struct Split {}
|
|
85
|
+
|
|
86
|
+
impl Split
|
|
87
|
+
{
|
|
88
|
+
fn call_impl(string: String, pat: String) -> FResult<Vec<graphcore::Value>>
|
|
89
|
+
{
|
|
90
|
+
Ok(string.split(&pat).map(|x: &str| x.into()).collect())
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
super::declare_function!(
|
|
95
|
+
split, Split, call_impl(String, String) -> String,
|
|
96
|
+
null_handling(null_returns_null, ignore, ignore)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
#[derive(Debug, Default)]
|
|
100
|
+
pub(super) struct Substring {}
|
|
101
|
+
|
|
102
|
+
impl Substring
|
|
103
|
+
{
|
|
104
|
+
fn call_impl(string: String, start: i64, length: i64) -> FResult<String>
|
|
105
|
+
{
|
|
106
|
+
use substring::Substring;
|
|
107
|
+
Ok(
|
|
108
|
+
string
|
|
109
|
+
.substring(start as usize, length as usize)
|
|
110
|
+
.to_string(),
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
super::declare_function!(
|
|
116
|
+
substring, Substring, call_impl(String, i64, i64) -> String,
|
|
117
|
+
null_handling(null_returns_null, ignore, ignore),
|
|
118
|
+
validate_args(ExpressionType::String | ExpressionType::Null, ExpressionType::Integer, ExpressionType::Integer),
|
|
119
|
+
default_args(2, i64::MAX)
|
|
120
|
+
);
|
|
121
|
+
|
|
5
122
|
#[derive(Debug, Default)]
|
|
6
123
|
pub(super) struct ToString {}
|
|
7
124
|
|
|
@@ -25,4 +142,9 @@ impl ToString
|
|
|
25
142
|
}
|
|
26
143
|
}
|
|
27
144
|
|
|
28
|
-
super::declare_function!(
|
|
145
|
+
super::declare_function!(
|
|
146
|
+
tostring, ToString,
|
|
147
|
+
call_impl(crate::value::Value) -> String,
|
|
148
|
+
null_handling(null_returns_null),
|
|
149
|
+
validate_args(ExpressionType::Boolean | ExpressionType::Integer | ExpressionType::Float | ExpressionType::String)
|
|
150
|
+
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
use std::{collections::HashMap, fmt::Debug, sync::Arc};
|
|
2
2
|
|
|
3
|
+
mod common;
|
|
3
4
|
mod containers;
|
|
4
5
|
mod edge;
|
|
5
6
|
mod math;
|
|
@@ -140,24 +141,48 @@ impl Manager
|
|
|
140
141
|
Self {
|
|
141
142
|
inner: ManagerInner {
|
|
142
143
|
functions: HashMap::from([
|
|
144
|
+
common::Size::create(),
|
|
143
145
|
containers::Head::create(),
|
|
144
146
|
containers::Keys::create(),
|
|
145
147
|
containers::Range::create(),
|
|
146
|
-
containers::Size::create(),
|
|
147
148
|
edge::Type::create(),
|
|
149
|
+
math::Acos::create(),
|
|
150
|
+
math::Asin::create(),
|
|
151
|
+
math::Atan::create(),
|
|
152
|
+
math::Atan2::create(),
|
|
148
153
|
math::Ceil::create(),
|
|
154
|
+
math::Cos::create(),
|
|
155
|
+
math::Cot::create(),
|
|
156
|
+
math::Degrees::create(),
|
|
157
|
+
math::E::create(),
|
|
158
|
+
math::Exp::create(),
|
|
149
159
|
math::Floor::create(),
|
|
160
|
+
math::Log::create(),
|
|
161
|
+
math::Log10::create(),
|
|
162
|
+
math::Pi::create(),
|
|
163
|
+
math::Radians::create(),
|
|
150
164
|
math::Rand::create(),
|
|
165
|
+
math::Sin::create(),
|
|
166
|
+
math::Tan::create(),
|
|
151
167
|
node::Labels::create(),
|
|
152
168
|
path::Length::create(),
|
|
153
169
|
path::Nodes::create(),
|
|
154
170
|
path::Edges::create(),
|
|
171
|
+
scalar::Abs::create(),
|
|
155
172
|
scalar::Coalesce::create(),
|
|
156
173
|
scalar::Id::create(),
|
|
157
174
|
scalar::Properties::create(),
|
|
158
175
|
scalar::ToBoolean::create(),
|
|
159
176
|
scalar::ToFloat::create(),
|
|
160
177
|
scalar::ToInteger::create(),
|
|
178
|
+
string::LTrim::create(),
|
|
179
|
+
string::RTrim::create(),
|
|
180
|
+
string::Trim::create(),
|
|
181
|
+
string::ToLower::create(),
|
|
182
|
+
string::ToUpper::create(),
|
|
183
|
+
string::Reverse::create(),
|
|
184
|
+
string::Split::create(),
|
|
185
|
+
string::Substring::create(),
|
|
161
186
|
string::ToString::create(),
|
|
162
187
|
value::HasLabel::create(),
|
|
163
188
|
value::HasLabels::create(),
|
|
@@ -264,6 +289,14 @@ macro_rules! make_function_call {
|
|
|
264
289
|
$crate::functions::make_function_argument!($function_name, arguments_iter, 1, $arg_type_1),
|
|
265
290
|
)
|
|
266
291
|
}};
|
|
292
|
+
($function_name: ident, $function: expr, $arguments: ident, $arg_type_0: ty, $arg_type_1: ty, $arg_type_2: ty, ) => {{
|
|
293
|
+
let mut arguments_iter = $arguments.into_iter();
|
|
294
|
+
$function(
|
|
295
|
+
$crate::functions::make_function_argument!($function_name, arguments_iter, 0, $arg_type_0),
|
|
296
|
+
$crate::functions::make_function_argument!($function_name, arguments_iter, 1, $arg_type_1),
|
|
297
|
+
$crate::functions::make_function_argument!($function_name, arguments_iter, 2, $arg_type_2),
|
|
298
|
+
)
|
|
299
|
+
}};
|
|
267
300
|
($function_name: ident, $function: expr, $arguments: ident, ) => {
|
|
268
301
|
$function()
|
|
269
302
|
};
|
|
@@ -308,34 +341,43 @@ macro_rules! default_validate_ {
|
|
|
308
341
|
|
|
309
342
|
#[rustfmt::skip]
|
|
310
343
|
macro_rules! validate_args_ {
|
|
311
|
-
($function_name: ident, $ret_type: ty, $( $expression_type: pat ),* ) => {
|
|
344
|
+
($function_name: ident, $min_arg_count: expr, $ret_type: ty, $( $expression_type: pat ),* ) => {
|
|
312
345
|
|args: Vec<$crate::compiler::expression_analyser::ExpressionType>|
|
|
313
346
|
-> crate::Result<$crate::compiler::expression_analyser::ExpressionType>
|
|
314
347
|
{
|
|
315
|
-
const
|
|
316
|
-
if args.len()
|
|
348
|
+
const MAX_ARG_COUNT: usize = $crate::functions::count_patterns!($( $expression_type,)*);
|
|
349
|
+
if args.len() > MAX_ARG_COUNT && args.len() < $min_arg_count
|
|
317
350
|
{
|
|
318
351
|
Err(crate::error::CompileTimeError::InvalidNumberOfArguments {
|
|
319
352
|
function_name: stringify!($function_name),
|
|
320
353
|
got: args.len(),
|
|
321
|
-
expected:
|
|
354
|
+
expected: $min_arg_count
|
|
322
355
|
})?;
|
|
323
356
|
}
|
|
324
357
|
let mut it = args.into_iter();
|
|
325
358
|
$(
|
|
326
|
-
|
|
359
|
+
if let Some(val) = it.next()
|
|
327
360
|
{
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
361
|
+
match val
|
|
362
|
+
{
|
|
363
|
+
$expression_type | ExpressionType::Variant => {}
|
|
364
|
+
_ => return Err(crate::error::CompileTimeError::InvalidArgumentType.into())
|
|
365
|
+
}
|
|
331
366
|
}
|
|
332
367
|
)*
|
|
368
|
+
Ok(<$ret_type>::result_type())
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
($function_name: ident, $ret_type: ty, $( $expression_type: pat ),* ) => {
|
|
372
|
+
{
|
|
373
|
+
const MIN_ARG_COUNT: usize = $crate::functions::count_patterns!($( $expression_type,)*);
|
|
374
|
+
$crate::functions::validate_args_!($function_name, MIN_ARG_COUNT, $ret_type, $( $expression_type ),* )
|
|
333
375
|
}
|
|
334
376
|
};
|
|
335
377
|
}
|
|
336
378
|
|
|
337
379
|
macro_rules! declare_function_ {
|
|
338
|
-
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, $
|
|
380
|
+
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, $null_handling: block, $validator: block , $default_args: block ) => {
|
|
339
381
|
impl $type_name
|
|
340
382
|
{
|
|
341
383
|
pub(super) fn create() -> (String, crate::functions::Function)
|
|
@@ -348,12 +390,13 @@ macro_rules! declare_function_ {
|
|
|
348
390
|
}
|
|
349
391
|
impl crate::functions::FunctionTrait for $type_name
|
|
350
392
|
{
|
|
351
|
-
fn call(&self, arguments: Vec<crate::value::Value>) -> crate::Result<crate::value::Value>
|
|
393
|
+
fn call(&self, mut arguments: Vec<crate::value::Value>) -> crate::Result<crate::value::Value>
|
|
352
394
|
{
|
|
353
395
|
const ARG_COUNT: usize = $crate::functions::count_arguments!($( $arg_type,)*);
|
|
396
|
+
($default_args)(&mut arguments);
|
|
354
397
|
if arguments.len() == ARG_COUNT
|
|
355
398
|
{
|
|
356
|
-
if
|
|
399
|
+
if $null_handling(&arguments)
|
|
357
400
|
{
|
|
358
401
|
return Ok(crate::value::Value::Null)
|
|
359
402
|
}
|
|
@@ -385,21 +428,102 @@ macro_rules! declare_function_ {
|
|
|
385
428
|
};
|
|
386
429
|
}
|
|
387
430
|
|
|
431
|
+
macro_rules! no_null_handling_ {
|
|
432
|
+
() => {
|
|
433
|
+
|_args: &Vec<graphcore::Value>| false
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
macro_rules! null_handling_once_ {
|
|
438
|
+
(null_returns_null, $iter: expr) => {
|
|
439
|
+
if $iter.next().map_or(true, |x| x.is_null())
|
|
440
|
+
{
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
(ignore, $iter: expr) => {
|
|
445
|
+
let _ = $iter.next();
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
macro_rules! null_handling_ {
|
|
450
|
+
( $( $null_mode: ident ),+ ) => {
|
|
451
|
+
|args: &Vec<graphcore::Value>| -> bool {
|
|
452
|
+
let mut iter = args.iter();
|
|
453
|
+
$( crate::functions::null_handling_once_!($null_mode, iter); )+
|
|
454
|
+
false
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
macro_rules! no_default_args_ {
|
|
460
|
+
() => {
|
|
461
|
+
|_args: &mut Vec<graphcore::Value>| {}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
macro_rules! default_args_ {
|
|
466
|
+
( $required: expr, $( $default_arg: expr ),+ ) => {
|
|
467
|
+
|args: &mut Vec<graphcore::Value>| {
|
|
468
|
+
if args.len() < $required
|
|
469
|
+
{
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
let mut current_idx = $required;
|
|
473
|
+
$(
|
|
474
|
+
if current_idx >= args.len()
|
|
475
|
+
{
|
|
476
|
+
args.push(($default_arg).into());
|
|
477
|
+
}
|
|
478
|
+
#[allow(unused_assignments)]
|
|
479
|
+
{
|
|
480
|
+
current_idx += 1;
|
|
481
|
+
}
|
|
482
|
+
)+
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
388
487
|
macro_rules! declare_function {
|
|
389
488
|
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty ) => {
|
|
390
489
|
$crate::functions::declare_function_!($function_name, $type_name,
|
|
391
|
-
$f_name ( $( $arg_type, )* ) -> $ret_type,
|
|
392
|
-
{$crate::functions::
|
|
490
|
+
$f_name ( $( $arg_type, )* ) -> $ret_type,
|
|
491
|
+
{$crate::functions::no_null_handling_!()},
|
|
492
|
+
{$crate::functions::default_validate_!($function_name, $ret_type)},
|
|
493
|
+
{$crate::functions::no_default_args_!()}
|
|
494
|
+
);
|
|
393
495
|
};
|
|
394
|
-
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty,
|
|
496
|
+
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, null_handling( $( $null_mode: ident ),+ ) ) => {
|
|
395
497
|
$crate::functions::declare_function_!($function_name, $type_name,
|
|
396
|
-
$f_name ( $( $arg_type, )* ) -> $ret_type,
|
|
397
|
-
{$crate::functions::
|
|
498
|
+
$f_name ( $( $arg_type, )* ) -> $ret_type,
|
|
499
|
+
{$crate::functions::null_handling_!($($null_mode),+)},
|
|
500
|
+
{$crate::functions::default_validate_!($function_name, $ret_type)},
|
|
501
|
+
{$crate::functions::no_default_args_!()}
|
|
502
|
+
);
|
|
398
503
|
};
|
|
399
504
|
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, validate_args( $( $expression_types: pat ),+ ) ) => {
|
|
400
505
|
$crate::functions::declare_function_!($function_name, $type_name,
|
|
401
|
-
$f_name ( $( $arg_type, )* ) -> $ret_type,
|
|
402
|
-
{$crate::functions::
|
|
506
|
+
$f_name ( $( $arg_type, )* ) -> $ret_type,
|
|
507
|
+
{$crate::functions::no_null_handling_!()},
|
|
508
|
+
{$crate::functions::validate_args_!($function_name, $ret_type, $( $expression_types ),+ )},
|
|
509
|
+
{$crate::functions::no_default_args_!()}
|
|
510
|
+
);
|
|
511
|
+
};
|
|
512
|
+
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, null_handling( $( $null_mode: ident ),+ ), validate_args( $( $expression_types: pat ),+ ) ) => {
|
|
513
|
+
$crate::functions::declare_function_!($function_name, $type_name,
|
|
514
|
+
$f_name ( $( $arg_type, )* ) -> $ret_type,
|
|
515
|
+
{$crate::functions::null_handling_!($($null_mode),+)},
|
|
516
|
+
{$crate::functions::validate_args_!($function_name, $ret_type, $( $expression_types ),+ )},
|
|
517
|
+
{$crate::functions::no_default_args_!()}
|
|
518
|
+
);
|
|
519
|
+
};
|
|
520
|
+
($function_name: ident, $type_name: ty, $f_name: ident ( $( $arg_type: ty $(,)? )* ) -> $ret_type: ty, null_handling( $( $null_mode: ident ),+ ), validate_args( $( $expression_types: pat ),+ ), default_args( $required: expr, $( $default_args: expr ),+ ) ) => {
|
|
521
|
+
$crate::functions::declare_function_!($function_name, $type_name,
|
|
522
|
+
$f_name ( $( $arg_type, )* ) -> $ret_type,
|
|
523
|
+
{$crate::functions::null_handling_!($($null_mode),+)},
|
|
524
|
+
{$crate::functions::validate_args_!($function_name, $required, $ret_type, $( $expression_types ),+ )},
|
|
525
|
+
{$crate::functions::default_args_!( $required, $($default_args),+)}
|
|
526
|
+
);
|
|
403
527
|
};
|
|
404
528
|
($function_name: ident, $type_name: ty, custom_trait ) => {
|
|
405
529
|
impl $type_name
|
|
@@ -415,11 +539,8 @@ macro_rules! declare_function {
|
|
|
415
539
|
};
|
|
416
540
|
}
|
|
417
541
|
|
|
418
|
-
pub(crate) use
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
pub(crate) use make_function_argument;
|
|
424
|
-
pub(crate) use make_function_call;
|
|
425
|
-
pub(crate) use validate_args_;
|
|
542
|
+
pub(crate) use {
|
|
543
|
+
count_arguments, count_patterns, declare_function, declare_function_, default_args_,
|
|
544
|
+
default_validate_, make_function_argument, make_function_call, no_default_args_,
|
|
545
|
+
no_null_handling_, null_handling_, null_handling_once_, validate_args_,
|
|
546
|
+
};
|
|
@@ -5,15 +5,15 @@ use ccutils::pool::{self, Pool};
|
|
|
5
5
|
use crate::{
|
|
6
6
|
prelude::*,
|
|
7
7
|
store::{
|
|
8
|
-
sqlbase::{SqlBindingValue, SqlResultValue},
|
|
9
8
|
TransactionBoxable,
|
|
9
|
+
sqlbase::{SqlBindingValue, SqlResultValue},
|
|
10
10
|
},
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
ccutils::assert_impl_all!(Store: Sync, Send);
|
|
14
14
|
|
|
15
15
|
use askama::Template;
|
|
16
|
-
use postgres::{types::ToSql
|
|
16
|
+
use postgres::{NoTls, types::ToSql};
|
|
17
17
|
|
|
18
18
|
const SCHEMA: &str = "public";
|
|
19
19
|
|
|
@@ -126,14 +126,12 @@ impl Drop for TransactionBase
|
|
|
126
126
|
fn drop(&mut self)
|
|
127
127
|
{
|
|
128
128
|
if *self.active.borrow()
|
|
129
|
+
&& let Err(e) = self.client.query("ROLLBACK", &[])
|
|
129
130
|
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
e
|
|
135
|
-
);
|
|
136
|
-
}
|
|
131
|
+
println!(
|
|
132
|
+
"Rollback failed with error {:?}, future use of the connection are likely to fail.",
|
|
133
|
+
e
|
|
134
|
+
);
|
|
137
135
|
}
|
|
138
136
|
}
|
|
139
137
|
}
|
|
@@ -336,7 +334,7 @@ impl Store
|
|
|
336
334
|
Ok(s)
|
|
337
335
|
}
|
|
338
336
|
fn upgrade_database(&self, _transaction: &mut TransactionBox, _from: utils::Version)
|
|
339
|
-
|
|
337
|
+
-> Result<()>
|
|
340
338
|
{
|
|
341
339
|
// No release with postgres, so nothing to upgrade
|
|
342
340
|
Ok(())
|
|
@@ -559,7 +557,7 @@ impl super::sqlbase::SqlQueries for Store
|
|
|
559
557
|
}
|
|
560
558
|
|
|
561
559
|
fn node_delete_query(graph_name: impl AsRef<str>, keys: impl AsRef<Vec<String>>)
|
|
562
|
-
|
|
560
|
+
-> Result<String>
|
|
563
561
|
{
|
|
564
562
|
Ok(
|
|
565
563
|
templates::NodeDelete {
|
|
@@ -608,7 +606,7 @@ impl super::sqlbase::SqlQueries for Store
|
|
|
608
606
|
)
|
|
609
607
|
}
|
|
610
608
|
fn edge_delete_query(graph_name: impl AsRef<str>, keys: impl AsRef<Vec<String>>)
|
|
611
|
-
|
|
609
|
+
-> Result<String>
|
|
612
610
|
{
|
|
613
611
|
Ok(
|
|
614
612
|
templates::EdgeDelete {
|
|
@@ -5,8 +5,8 @@ use ccutils::pool::{self, Pool};
|
|
|
5
5
|
use crate::{
|
|
6
6
|
prelude::*,
|
|
7
7
|
store::{
|
|
8
|
-
sqlbase::{SqlBindingValue, SqlResultValue},
|
|
9
8
|
TransactionBoxable,
|
|
9
|
+
sqlbase::{SqlBindingValue, SqlResultValue},
|
|
10
10
|
},
|
|
11
11
|
utils::hex,
|
|
12
12
|
};
|
|
@@ -84,14 +84,12 @@ impl Drop for TransactionBase
|
|
|
84
84
|
fn drop(&mut self)
|
|
85
85
|
{
|
|
86
86
|
if *self.active.borrow()
|
|
87
|
+
&& let Err(e) = self.connection.execute("ROLLBACK", ())
|
|
87
88
|
{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
e
|
|
93
|
-
);
|
|
94
|
-
}
|
|
89
|
+
println!(
|
|
90
|
+
"Rollback failed with error {:?}, future use of the connection are likely to fail.",
|
|
91
|
+
e
|
|
92
|
+
);
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
95
|
}
|
|
@@ -578,7 +576,7 @@ impl super::sqlbase::SqlQueries for Store
|
|
|
578
576
|
}
|
|
579
577
|
|
|
580
578
|
fn node_delete_query(graph_name: impl AsRef<str>, keys: impl AsRef<Vec<String>>)
|
|
581
|
-
|
|
579
|
+
-> Result<String>
|
|
582
580
|
{
|
|
583
581
|
Ok(
|
|
584
582
|
templates::NodeDelete {
|
|
@@ -627,7 +625,7 @@ impl super::sqlbase::SqlQueries for Store
|
|
|
627
625
|
)
|
|
628
626
|
}
|
|
629
627
|
fn edge_delete_query(graph_name: impl AsRef<str>, keys: impl AsRef<Vec<String>>)
|
|
630
|
-
|
|
628
|
+
-> Result<String>
|
|
631
629
|
{
|
|
632
630
|
Ok(
|
|
633
631
|
templates::EdgeDelete {
|
data/ext/gqlitedb/src/store.rs
CHANGED
|
@@ -286,27 +286,21 @@ impl SelectNodeQuery
|
|
|
286
286
|
return true;
|
|
287
287
|
}
|
|
288
288
|
if let Some(keys) = &self.keys
|
|
289
|
+
&& !keys.iter().any(|x| node.key() == *x)
|
|
289
290
|
{
|
|
290
|
-
|
|
291
|
-
{
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
291
|
+
return false;
|
|
294
292
|
}
|
|
295
293
|
if let Some(labels) = &self.labels
|
|
294
|
+
&& !labels.iter().all(|x| node.labels().contains(x))
|
|
296
295
|
{
|
|
297
|
-
|
|
298
|
-
{
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
296
|
+
return false;
|
|
301
297
|
}
|
|
302
298
|
if let Some(properties) = &self.properties
|
|
303
|
-
|
|
304
|
-
if !properties
|
|
299
|
+
&& !properties
|
|
305
300
|
.iter()
|
|
306
301
|
.all(|(k, v)| node.properties().get(k) == Some(v))
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
302
|
+
{
|
|
303
|
+
return false;
|
|
310
304
|
}
|
|
311
305
|
true
|
|
312
306
|
}
|
|
@@ -414,28 +408,25 @@ impl SelectEdgeQuery
|
|
|
414
408
|
pub(crate) fn is_match(&self, edge: &graph::Path) -> bool
|
|
415
409
|
{
|
|
416
410
|
if let Some(keys) = &self.keys
|
|
411
|
+
&& !keys.iter().any(|x| edge.key() == *x)
|
|
417
412
|
{
|
|
418
|
-
|
|
419
|
-
{
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
413
|
+
return false;
|
|
422
414
|
}
|
|
415
|
+
|
|
423
416
|
if let Some(labels) = &self.labels
|
|
417
|
+
&& !labels.iter().all(|x| edge.labels().contains(x))
|
|
424
418
|
{
|
|
425
|
-
|
|
426
|
-
{
|
|
427
|
-
return false;
|
|
428
|
-
}
|
|
419
|
+
return false;
|
|
429
420
|
}
|
|
421
|
+
|
|
430
422
|
if let Some(properties) = &self.properties
|
|
431
|
-
|
|
432
|
-
if !properties
|
|
423
|
+
&& !properties
|
|
433
424
|
.iter()
|
|
434
425
|
.all(|(k, v)| edge.properties().get(k) == Some(v))
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
426
|
+
{
|
|
427
|
+
return false;
|
|
438
428
|
}
|
|
429
|
+
|
|
439
430
|
self.source.is_match(edge.source()) && self.destination.is_match(edge.destination())
|
|
440
431
|
}
|
|
441
432
|
}
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gqlite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.5.
|
|
4
|
+
version: 1.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cyrille Berger
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rb_sys
|
|
@@ -56,7 +55,6 @@ description: "GQLite is a Rust-language library, with a C interface, that implem
|
|
|
56
55
|
=> ex\n # Report any error\n puts \"An error has occured: #{ex.message}\"\nend\n\n```\n\nThe
|
|
57
56
|
documentation for the GQL query language can found in [OpenCypher](https://auksys.org/documentation/5/libraries/gqlite/opencypher/)
|
|
58
57
|
and for the [API](https://auksys.org/documentation/5/libraries/gqlite/api/).\n\n"
|
|
59
|
-
email:
|
|
60
58
|
executables: []
|
|
61
59
|
extensions:
|
|
62
60
|
- ext/gqliterb/extconf.rb
|
|
@@ -83,6 +81,7 @@ files:
|
|
|
83
81
|
- ext/gqlitedb/src/consts.rs
|
|
84
82
|
- ext/gqlitedb/src/error.rs
|
|
85
83
|
- ext/gqlitedb/src/functions.rs
|
|
84
|
+
- ext/gqlitedb/src/functions/common.rs
|
|
86
85
|
- ext/gqlitedb/src/functions/containers.rs
|
|
87
86
|
- ext/gqlitedb/src/functions/edge.rs
|
|
88
87
|
- ext/gqlitedb/src/functions/math.rs
|
|
@@ -186,7 +185,6 @@ homepage: https://gitlab.com/auksys/gqlite
|
|
|
186
185
|
licenses:
|
|
187
186
|
- MIT
|
|
188
187
|
metadata: {}
|
|
189
|
-
post_install_message:
|
|
190
188
|
rdoc_options: []
|
|
191
189
|
require_paths:
|
|
192
190
|
- lib
|
|
@@ -201,8 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
201
199
|
- !ruby/object:Gem::Version
|
|
202
200
|
version: '0'
|
|
203
201
|
requirements: []
|
|
204
|
-
rubygems_version: 3.
|
|
205
|
-
signing_key:
|
|
202
|
+
rubygems_version: 3.6.7
|
|
206
203
|
specification_version: 4
|
|
207
204
|
summary: Ruby bindings for GQLite, a Graph Query library.
|
|
208
205
|
test_files: []
|