Skip to content

Commit 5cbe79e

Browse files
authored
Add Serde json to partiql-value (#289)
Adds the serde-json's Serialize and Deseralize to partiql_value::Value as a feature.
1 parent e36e4e1 commit 5cbe79e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
### Added
1212
- Adds some benchmarks for parsing, compiling, planning, & evaluation
1313
- Implements `PIVOT` operator in evaluator
14+
- `serde` feature to `partiql-value` with `Serialize` and `Deserialize` json serde.
1415

1516
### Fixes
1617

partiql-value/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ itertools = "0.10.*"
2626
unicase = "2.*"
2727
rust_decimal = { version = "1.25.0", default-features = false, features = ["std"] }
2828
rust_decimal_macros = "1.26"
29+
serde = { version = "1.*", features = ["derive"], optional = true }
2930
ion-rs = "0.14"
3031

3132
[dev-dependencies]
3233
criterion = "0.4"
34+
35+
[features]
36+
default = []
37+
serde = [
38+
"dep:serde",
39+
"rust_decimal/serde-with-str",
40+
"rust_decimal/serde",
41+
"ordered-float/serde"
42+
]

partiql-value/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ use unicase::UniCase;
1515

1616
mod ion;
1717

18+
#[cfg(feature = "serde")]
19+
use serde::{Deserialize, Serialize};
20+
1821
#[derive(Clone, Hash, Debug, Eq, PartialEq)]
1922
pub enum BindingsName {
2023
CaseSensitive(String),
@@ -26,6 +29,7 @@ pub enum BindingsName {
2629
#[derive(Hash, PartialEq, Eq, Clone)]
2730
#[allow(dead_code)] // TODO remove once out of PoC
2831
#[derive(Default)]
32+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2933
pub enum Value {
3034
Null,
3135
#[default]
@@ -848,6 +852,7 @@ impl From<Bag> for Value {
848852
}
849853

850854
#[derive(Default, Hash, PartialEq, Eq, Clone)]
855+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
851856
/// Represents a PartiQL List value, e.g. [1, 2, 'one']
852857
pub struct List(Vec<Value>);
853858

@@ -999,6 +1004,7 @@ impl Ord for List {
9991004
}
10001005

10011006
#[derive(Default, Eq, Clone)]
1007+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10021008
/// Represents a PartiQL BAG value, e.g.: <<1, 'two', 4>>
10031009
pub struct Bag(Vec<Value>);
10041010

@@ -1156,6 +1162,7 @@ impl Hash for Bag {
11561162
}
11571163

11581164
#[derive(Default, Eq, Clone)]
1165+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11591166
pub struct Tuple {
11601167
attrs: Vec<String>,
11611168
vals: Vec<Value>,

0 commit comments

Comments
 (0)