gqlite 1.3.0 → 1.4.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 +4 -3
- data/ext/gqlitedb/Cargo.toml +7 -4
- data/ext/gqlitedb/src/aggregators/arithmetic.rs +1 -0
- data/ext/gqlitedb/src/compiler/expression_analyser.rs +2 -0
- data/ext/gqlitedb/src/compiler.rs +31 -19
- data/ext/gqlitedb/src/connection.rs +42 -7
- data/ext/gqlitedb/src/error.rs +3 -0
- data/ext/gqlitedb/src/functions/containers.rs +1 -1
- data/ext/gqlitedb/src/functions/path.rs +1 -1
- data/ext/gqlitedb/src/functions/scalar.rs +23 -0
- data/ext/gqlitedb/src/functions.rs +8 -0
- data/ext/gqlitedb/src/interpreter/evaluators.rs +10 -10
- data/ext/gqlitedb/src/interpreter/instructions.rs +3 -3
- data/ext/gqlitedb/src/lib.rs +1 -3
- data/ext/gqlitedb/src/parser/ast.rs +1 -0
- data/ext/gqlitedb/src/parser/gql.pest +3 -1
- data/ext/gqlitedb/src/parser/parser_impl.rs +8 -0
- data/ext/gqlitedb/src/prelude.rs +3 -0
- data/ext/gqlitedb/src/store/{pgql.rs → pgrx.rs} +2 -0
- data/ext/gqlitedb/src/store/postgres.rs +0 -0
- data/ext/gqlitedb/src/store/sqlbase/sqlmetadata.rs +117 -0
- data/ext/gqlitedb/src/store/sqlbase/sqlqueries.rs +62 -0
- data/ext/gqlitedb/src/store/sqlbase/sqlstore.rs +55 -0
- data/ext/gqlitedb/src/store/sqlbase/sqlvalue.rs +189 -0
- data/ext/gqlitedb/src/store/sqlbase.rs +456 -0
- data/ext/gqlitedb/src/store/sqlite.rs +271 -573
- data/ext/gqlitedb/src/store.rs +7 -5
- data/ext/gqlitedb/src/tests/templates/programs.rs +10 -10
- data/ext/gqlitedb/src/utils.rs +25 -0
- data/ext/gqlitedb/src/value/compare.rs +6 -0
- data/ext/gqlitedb/src/value.rs +18 -2
- data/ext/gqlitedb/templates/sql/sqlite/edge_select.sql +18 -18
- data/ext/gqlitedb/templates/sql/sqlite/edge_update.sql +3 -3
- data/ext/gqlitedb/templates/sql/sqlite/node_select.sql +6 -6
- data/ext/gqlitedb/templates/sql/sqlite/node_update.sql +3 -3
- data/ext/gqliterb/src/lib.rs +30 -2
- data/ext/graphcore/Cargo.toml +3 -2
- data/ext/graphcore/src/error.rs +2 -0
- data/ext/graphcore/src/lib.rs +2 -1
- data/ext/graphcore/src/prelude.rs +1 -1
- data/ext/graphcore/src/table.rs +1 -1
- data/ext/graphcore/src/timestamp.rs +104 -0
- data/ext/graphcore/src/value.rs +106 -23
- metadata +10 -7
- data/ext/gqlitedb/gqlite_bench_data/README.MD +0 -6
- data/ext/gqlitedb/gqlite_bench_data/scripts/generate_smaller_pokec.rb +0 -85
- data/ext/gqlitedb/gqlite_bench_data/scripts/to_efficient_pokec.rb +0 -34
- data/ext/graphcore/release.toml +0 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
use serde::{Deserialize, Serialize};
|
|
2
|
+
|
|
3
|
+
use super::{FromSqlValue, SqlValue};
|
|
4
|
+
use crate::prelude::*;
|
|
5
|
+
|
|
6
|
+
pub(crate) trait SqlMetaDataQueries
|
|
7
|
+
{
|
|
8
|
+
fn metadata_get_query() -> Result<String>;
|
|
9
|
+
fn metadata_set_query() -> Result<String>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
pub(crate) trait SqlMetaDataStore: super::SqlStore
|
|
13
|
+
{
|
|
14
|
+
/// Get the metavalue
|
|
15
|
+
fn get_optional_metadata_value<T: FromSqlValue>(
|
|
16
|
+
&self,
|
|
17
|
+
transaction: &mut Self::TransactionBox,
|
|
18
|
+
key: impl Into<String>,
|
|
19
|
+
) -> Result<Option<T>>;
|
|
20
|
+
fn get_metadata_value<T: FromSqlValue>(
|
|
21
|
+
&self,
|
|
22
|
+
transaction: &mut Self::TransactionBox,
|
|
23
|
+
key: impl Into<String>,
|
|
24
|
+
) -> Result<T>
|
|
25
|
+
{
|
|
26
|
+
let key = key.into();
|
|
27
|
+
self
|
|
28
|
+
.get_optional_metadata_value(transaction, &key)?
|
|
29
|
+
.ok_or_else(|| InternalError::MissingMetadata { key }.into())
|
|
30
|
+
}
|
|
31
|
+
#[allow(dead_code)]
|
|
32
|
+
fn get_metadata_value_or_else<T: FromSqlValue>(
|
|
33
|
+
&self,
|
|
34
|
+
transaction: &mut Self::TransactionBox,
|
|
35
|
+
key: impl Into<String>,
|
|
36
|
+
f: impl FnOnce() -> T,
|
|
37
|
+
) -> Result<T>
|
|
38
|
+
{
|
|
39
|
+
let v = self.get_optional_metadata_value(transaction, key)?;
|
|
40
|
+
Ok(v.unwrap_or_else(f))
|
|
41
|
+
}
|
|
42
|
+
/// Get the metadata value and deserialize it from JSON.
|
|
43
|
+
fn get_metadata_value_json<T: for<'a> Deserialize<'a>>(
|
|
44
|
+
&self,
|
|
45
|
+
transaction: &mut Self::TransactionBox,
|
|
46
|
+
key: impl Into<String>,
|
|
47
|
+
) -> Result<T>
|
|
48
|
+
{
|
|
49
|
+
Ok(serde_json::from_str(
|
|
50
|
+
&self.get_metadata_value::<String>(transaction, key)?,
|
|
51
|
+
)?)
|
|
52
|
+
}
|
|
53
|
+
#[allow(dead_code)]
|
|
54
|
+
fn get_metadata_value_json_or_else<T: for<'a> Deserialize<'a>>(
|
|
55
|
+
&self,
|
|
56
|
+
transaction: &mut Self::TransactionBox,
|
|
57
|
+
key: impl Into<String>,
|
|
58
|
+
f: impl FnOnce() -> T,
|
|
59
|
+
) -> Result<T>
|
|
60
|
+
{
|
|
61
|
+
let v = self.get_optional_metadata_value::<String>(transaction, key)?;
|
|
62
|
+
v.map_or_else(|| Ok(f()), |x| Ok(serde_json::from_str(&x)?))
|
|
63
|
+
}
|
|
64
|
+
fn set_metadata_value<'a>(
|
|
65
|
+
&self,
|
|
66
|
+
transaction: &mut Self::TransactionBox,
|
|
67
|
+
key: impl Into<String>,
|
|
68
|
+
value: impl Into<SqlValue<'a>>,
|
|
69
|
+
) -> Result<()>;
|
|
70
|
+
/// Serialize a value to JSON and store the result in the database.
|
|
71
|
+
fn set_metadata_value_json(
|
|
72
|
+
&self,
|
|
73
|
+
transaction: &mut Self::TransactionBox,
|
|
74
|
+
key: impl Into<String>,
|
|
75
|
+
value: &impl Serialize,
|
|
76
|
+
) -> Result<()>
|
|
77
|
+
{
|
|
78
|
+
self.set_metadata_value(transaction, key, &serde_json::to_string(value)?)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
impl<TStore> SqlMetaDataStore for TStore
|
|
83
|
+
where
|
|
84
|
+
TStore: super::SqlStore + SqlMetaDataQueries,
|
|
85
|
+
{
|
|
86
|
+
fn get_optional_metadata_value<T: FromSqlValue>(
|
|
87
|
+
&self,
|
|
88
|
+
transaction: &mut Self::TransactionBox,
|
|
89
|
+
key: impl Into<String>,
|
|
90
|
+
) -> Result<Option<T>>
|
|
91
|
+
{
|
|
92
|
+
let mut res = None;
|
|
93
|
+
self.query_rows(
|
|
94
|
+
transaction,
|
|
95
|
+
Self::metadata_get_query()?,
|
|
96
|
+
(&key.into(),),
|
|
97
|
+
|x| {
|
|
98
|
+
res = Some(x.get(0)?);
|
|
99
|
+
Ok(())
|
|
100
|
+
},
|
|
101
|
+
)?;
|
|
102
|
+
Ok(res)
|
|
103
|
+
}
|
|
104
|
+
fn set_metadata_value<'a>(
|
|
105
|
+
&self,
|
|
106
|
+
transaction: &mut Self::TransactionBox,
|
|
107
|
+
key: impl Into<String>,
|
|
108
|
+
value: impl Into<SqlValue<'a>>,
|
|
109
|
+
) -> Result<()>
|
|
110
|
+
{
|
|
111
|
+
self.execute(
|
|
112
|
+
transaction,
|
|
113
|
+
Self::metadata_set_query()?,
|
|
114
|
+
(&key.into(), value.into()),
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
use crate::prelude::*;
|
|
2
|
+
|
|
3
|
+
pub(crate) trait SqlQueries
|
|
4
|
+
{
|
|
5
|
+
/// Query for creating a new graph.
|
|
6
|
+
fn graph_create_query(graph_name: impl AsRef<str>) -> Result<String>;
|
|
7
|
+
/// Query for deleting a graph.
|
|
8
|
+
fn graph_delete(graph_name: impl AsRef<str>) -> Result<String>;
|
|
9
|
+
/// Query for creating a new node
|
|
10
|
+
fn node_create_query(graph_name: impl AsRef<str>) -> Result<String>;
|
|
11
|
+
/// Query for deleting the nodes.
|
|
12
|
+
fn node_delete_query(
|
|
13
|
+
graph_name: impl AsRef<str>,
|
|
14
|
+
keys: impl AsRef<Vec<String>>,
|
|
15
|
+
) -> Result<String>;
|
|
16
|
+
/// Query for updating a node.
|
|
17
|
+
fn node_update_query(graph_name: impl AsRef<str>) -> Result<String>;
|
|
18
|
+
/// Query for selecting a node.
|
|
19
|
+
fn node_select_query(
|
|
20
|
+
graph_name: impl AsRef<str>,
|
|
21
|
+
keys_var: Option<usize>,
|
|
22
|
+
labels_var: Option<usize>,
|
|
23
|
+
properties_var: Option<usize>,
|
|
24
|
+
) -> Result<String>;
|
|
25
|
+
/// Query for createing an edge.
|
|
26
|
+
fn edge_create_query(graph_name: impl AsRef<str>) -> Result<String>;
|
|
27
|
+
/// Query for deleting the edges.
|
|
28
|
+
fn edge_delete_query(
|
|
29
|
+
graph_name: impl AsRef<str>,
|
|
30
|
+
keys: impl AsRef<Vec<String>>,
|
|
31
|
+
) -> Result<String>;
|
|
32
|
+
/// Query for updating a node.
|
|
33
|
+
fn edge_update_query(graph_name: impl AsRef<str>) -> Result<String>;
|
|
34
|
+
/// Query for deleting edges for the given nodes.
|
|
35
|
+
fn edge_delete_by_nodes_query(
|
|
36
|
+
graph_name: impl AsRef<str>,
|
|
37
|
+
keys: impl AsRef<Vec<String>>,
|
|
38
|
+
) -> Result<String>;
|
|
39
|
+
/// Query for the number of edges connected to the nodes.
|
|
40
|
+
fn edge_count_for_nodes_query(
|
|
41
|
+
graph_name: impl AsRef<str>,
|
|
42
|
+
keys: impl AsRef<Vec<String>>,
|
|
43
|
+
) -> Result<String>;
|
|
44
|
+
/// Query for selecting an edge.
|
|
45
|
+
#[allow(clippy::too_many_arguments)]
|
|
46
|
+
fn edge_select_query(
|
|
47
|
+
graph_name: impl AsRef<str>,
|
|
48
|
+
is_undirected: bool,
|
|
49
|
+
table_suffix: impl AsRef<str>,
|
|
50
|
+
edge_keys_var: Option<usize>,
|
|
51
|
+
edge_labels_var: Option<usize>,
|
|
52
|
+
edge_properties_var: Option<usize>,
|
|
53
|
+
left_keys_var: Option<usize>,
|
|
54
|
+
left_labels_var: Option<usize>,
|
|
55
|
+
left_properties_var: Option<usize>,
|
|
56
|
+
right_keys_var: Option<usize>,
|
|
57
|
+
right_labels_var: Option<usize>,
|
|
58
|
+
right_properties_var: Option<usize>,
|
|
59
|
+
) -> Result<String>;
|
|
60
|
+
/// Query for computing statistics.
|
|
61
|
+
fn compute_statistics_query(graph_name: impl AsRef<str>) -> Result<String>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
use crate::{prelude::*, store::TransactionBoxable};
|
|
2
|
+
|
|
3
|
+
use super::{FromSqlValue, IntoBindings, SqlValue};
|
|
4
|
+
|
|
5
|
+
pub(crate) trait Row: Sized
|
|
6
|
+
{
|
|
7
|
+
fn get<T: FromSqlValue>(&self, index: usize) -> Result<T>
|
|
8
|
+
{
|
|
9
|
+
T::from_sql_value(self.get_value(index)?)
|
|
10
|
+
}
|
|
11
|
+
fn get_value(&self, index: usize) -> Result<SqlValue<'_>>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/// Base trait for SQL Store.
|
|
15
|
+
pub(crate) trait SqlStore
|
|
16
|
+
{
|
|
17
|
+
type TransactionBox: TransactionBoxable;
|
|
18
|
+
type Row<'a>: Row;
|
|
19
|
+
/// Initialise an SQL store
|
|
20
|
+
fn initialise(&self) -> Result<()>;
|
|
21
|
+
|
|
22
|
+
/// Begin a read transaction.
|
|
23
|
+
fn begin_sql_read(&self) -> Result<Self::TransactionBox>;
|
|
24
|
+
/// Begin a write transaction.
|
|
25
|
+
fn begin_sql_write(&self) -> Result<Self::TransactionBox>;
|
|
26
|
+
/// Execute a batch of SQL queries for the given transaction.
|
|
27
|
+
fn execute_batch(
|
|
28
|
+
&self,
|
|
29
|
+
transaction: &mut Self::TransactionBox,
|
|
30
|
+
sql: impl AsRef<str>,
|
|
31
|
+
) -> Result<()>;
|
|
32
|
+
/// Execute a single SQL query for the given transaction.
|
|
33
|
+
fn execute<'a>(
|
|
34
|
+
&self,
|
|
35
|
+
transaction: &mut Self::TransactionBox,
|
|
36
|
+
sql: impl AsRef<str>,
|
|
37
|
+
bindings: impl IntoBindings<'a>,
|
|
38
|
+
) -> Result<()>;
|
|
39
|
+
/// Execute a SQL Query that return a single row.
|
|
40
|
+
fn query_row<'a, 'tx, T>(
|
|
41
|
+
&self,
|
|
42
|
+
transaction: &'tx mut Self::TransactionBox,
|
|
43
|
+
sql: impl AsRef<str>,
|
|
44
|
+
bindings: impl IntoBindings<'a>,
|
|
45
|
+
f: impl for<'b> FnOnce(&Self::Row<'b>) -> Result<T>,
|
|
46
|
+
) -> Result<T>;
|
|
47
|
+
/// Execute a SQL Query that return multiple rows.
|
|
48
|
+
fn query_rows<'a, 'tx>(
|
|
49
|
+
&self,
|
|
50
|
+
transaction: &'tx mut Self::TransactionBox,
|
|
51
|
+
sql: impl AsRef<str>,
|
|
52
|
+
bindings: impl IntoBindings<'a>,
|
|
53
|
+
f: impl for<'b> FnMut(&Self::Row<'b>) -> Result<()>,
|
|
54
|
+
) -> Result<()>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
use crate::prelude::*;
|
|
2
|
+
|
|
3
|
+
#[derive(Debug)]
|
|
4
|
+
pub(crate) enum SqlValue<'a>
|
|
5
|
+
{
|
|
6
|
+
StringRef(&'a String),
|
|
7
|
+
String(String),
|
|
8
|
+
Key(&'a graph::Key),
|
|
9
|
+
Blob(&'a [u8]),
|
|
10
|
+
Text(&'a [u8]),
|
|
11
|
+
Float(f64),
|
|
12
|
+
Integer(i64),
|
|
13
|
+
Null,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
impl<'a> From<&'a String> for SqlValue<'a>
|
|
17
|
+
{
|
|
18
|
+
fn from(val: &'a String) -> Self
|
|
19
|
+
{
|
|
20
|
+
SqlValue::StringRef(val)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
impl<'a> From<String> for SqlValue<'a>
|
|
25
|
+
{
|
|
26
|
+
fn from(val: String) -> Self
|
|
27
|
+
{
|
|
28
|
+
SqlValue::String(val)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl<'a> From<&'a graph::Key> for SqlValue<'a>
|
|
33
|
+
{
|
|
34
|
+
fn from(val: &'a graph::Key) -> Self
|
|
35
|
+
{
|
|
36
|
+
SqlValue::Key(val)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub(crate) trait IntoBindings<'a>
|
|
41
|
+
{
|
|
42
|
+
fn into_bindings_iter(self) -> impl Iterator<Item = SqlValue<'a>>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
impl<'a> IntoBindings<'a> for ()
|
|
46
|
+
{
|
|
47
|
+
fn into_bindings_iter(self) -> impl Iterator<Item = SqlValue<'a>>
|
|
48
|
+
{
|
|
49
|
+
vec![].into_iter()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
impl<'a, T0> IntoBindings<'a> for (T0,)
|
|
54
|
+
where
|
|
55
|
+
T0: Into<SqlValue<'a>>,
|
|
56
|
+
{
|
|
57
|
+
fn into_bindings_iter(self) -> impl Iterator<Item = SqlValue<'a>>
|
|
58
|
+
{
|
|
59
|
+
vec![self.0.into()].into_iter()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
impl<'a, T0, T1> IntoBindings<'a> for (T0, T1)
|
|
64
|
+
where
|
|
65
|
+
T0: Into<SqlValue<'a>>,
|
|
66
|
+
T1: Into<SqlValue<'a>>,
|
|
67
|
+
{
|
|
68
|
+
fn into_bindings_iter(self) -> impl Iterator<Item = SqlValue<'a>>
|
|
69
|
+
{
|
|
70
|
+
vec![self.0.into(), self.1.into()].into_iter()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
impl<'a, T0, T1, T2> IntoBindings<'a> for (T0, T1, T2)
|
|
75
|
+
where
|
|
76
|
+
T0: Into<SqlValue<'a>>,
|
|
77
|
+
T1: Into<SqlValue<'a>>,
|
|
78
|
+
T2: Into<SqlValue<'a>>,
|
|
79
|
+
{
|
|
80
|
+
fn into_bindings_iter(self) -> impl Iterator<Item = SqlValue<'a>>
|
|
81
|
+
{
|
|
82
|
+
vec![self.0.into(), self.1.into(), self.2.into()].into_iter()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
impl<'a, T0, T1, T2, T3, T4> IntoBindings<'a> for (T0, T1, T2, T3, T4)
|
|
87
|
+
where
|
|
88
|
+
T0: Into<SqlValue<'a>>,
|
|
89
|
+
T1: Into<SqlValue<'a>>,
|
|
90
|
+
T2: Into<SqlValue<'a>>,
|
|
91
|
+
T3: Into<SqlValue<'a>>,
|
|
92
|
+
T4: Into<SqlValue<'a>>,
|
|
93
|
+
{
|
|
94
|
+
fn into_bindings_iter(self) -> impl Iterator<Item = SqlValue<'a>>
|
|
95
|
+
{
|
|
96
|
+
vec![
|
|
97
|
+
self.0.into(),
|
|
98
|
+
self.1.into(),
|
|
99
|
+
self.2.into(),
|
|
100
|
+
self.3.into(),
|
|
101
|
+
self.4.into(),
|
|
102
|
+
]
|
|
103
|
+
.into_iter()
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
impl<'a> IntoBindings<'a> for Vec<SqlValue<'a>>
|
|
108
|
+
{
|
|
109
|
+
fn into_bindings_iter(self) -> impl Iterator<Item = SqlValue<'a>>
|
|
110
|
+
{
|
|
111
|
+
self.into_iter()
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
pub(crate) trait FromSqlValue: Sized
|
|
116
|
+
{
|
|
117
|
+
fn from_sql_value<'a>(value: SqlValue<'a>) -> Result<Self>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
impl FromSqlValue for String
|
|
121
|
+
{
|
|
122
|
+
fn from_sql_value<'a>(value: SqlValue<'a>) -> Result<Self>
|
|
123
|
+
{
|
|
124
|
+
match value
|
|
125
|
+
{
|
|
126
|
+
SqlValue::Text(text) => Ok(std::str::from_utf8(text)?.to_string()),
|
|
127
|
+
SqlValue::String(string) => Ok(string),
|
|
128
|
+
SqlValue::StringRef(string) => Ok(string.clone()),
|
|
129
|
+
_ =>
|
|
130
|
+
{
|
|
131
|
+
println!("{:?} to string", value);
|
|
132
|
+
Err(InternalError::InvalidQueryResultCast.into())
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
impl FromSqlValue for usize
|
|
139
|
+
{
|
|
140
|
+
fn from_sql_value<'a>(value: SqlValue<'a>) -> Result<Self>
|
|
141
|
+
{
|
|
142
|
+
match value
|
|
143
|
+
{
|
|
144
|
+
SqlValue::Integer(i) => Ok(i as usize),
|
|
145
|
+
_ =>
|
|
146
|
+
{
|
|
147
|
+
println!("{:?} to usize", value);
|
|
148
|
+
Err(InternalError::InvalidQueryResultCast.into())
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
impl FromSqlValue for u32
|
|
155
|
+
{
|
|
156
|
+
fn from_sql_value<'a>(value: SqlValue<'a>) -> Result<Self>
|
|
157
|
+
{
|
|
158
|
+
match value
|
|
159
|
+
{
|
|
160
|
+
SqlValue::Integer(i) => Ok(i as u32),
|
|
161
|
+
_ =>
|
|
162
|
+
{
|
|
163
|
+
println!("{:?} to u32", value);
|
|
164
|
+
Err(InternalError::InvalidQueryResultCast.into())
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
impl FromSqlValue for graph::Key
|
|
171
|
+
{
|
|
172
|
+
fn from_sql_value<'a>(value: SqlValue<'a>) -> Result<Self>
|
|
173
|
+
{
|
|
174
|
+
match value
|
|
175
|
+
{
|
|
176
|
+
SqlValue::Integer(i) => Ok(graphcore::Key::new(i as u128)),
|
|
177
|
+
SqlValue::Key(k) => Ok(*k),
|
|
178
|
+
SqlValue::Blob(b) => <[u8; 16]>::try_from(b)
|
|
179
|
+
.map(u128::from_be_bytes)
|
|
180
|
+
.map(graphcore::Key::new)
|
|
181
|
+
.map_err(|_| InternalError::InvalidQueryResultCast.into()),
|
|
182
|
+
_ =>
|
|
183
|
+
{
|
|
184
|
+
println!("{:?} to key", value);
|
|
185
|
+
Err(InternalError::InvalidQueryResultCast.into())
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|