Skip to content

Commit

Permalink
feat(quaint): remove "json" conditional flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno committed Sep 13, 2023
1 parent 5106138 commit 25a7735
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 238 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/quaint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
features:
- "--lib --features=all"
- "--lib --no-default-features --features=sqlite"
- "--lib --no-default-features --features=sqlite --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=sqlite --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql"
- "--lib --no-default-features --features=postgresql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql"
- "--lib --no-default-features --features=mysql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql"
- "--lib --no-default-features --features=mssql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--doc --features=all"
env:
TEST_MYSQL: "mysql://root:prisma@localhost:3306/prisma"
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ features = [
"bigdecimal",
"expose-drivers",
"fmt-sql",
"json",
"mssql",
"mysql",
"pooled",
Expand Down
8 changes: 4 additions & 4 deletions quaint/.github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ jobs:
features:
- "--lib --features=all"
- "--lib --no-default-features --features=sqlite"
- "--lib --no-default-features --features=sqlite --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=sqlite --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql"
- "--lib --no-default-features --features=postgresql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql"
- "--lib --no-default-features --features=mysql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql"
- "--lib --no-default-features --features=mssql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--doc --features=all"
env:
TEST_MYSQL: "mysql://root:prisma@localhost:3306/prisma"
Expand Down
6 changes: 2 additions & 4 deletions quaint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ docs = []
expose-drivers = []

all = [
"json",
"mssql",
"mysql",
"pooled",
Expand Down Expand Up @@ -58,7 +57,6 @@ postgresql = [
"byteorder",
]

json = ["serde_json", "base64"]
mssql = ["tiberius", "uuid", "tokio-util", "tokio/time", "tokio/net", "either"]
mysql = ["mysql_async", "tokio/time", "lru-cache"]
pooled = ["mobc"]
Expand All @@ -81,10 +79,10 @@ url = "2.1"
hex = "0.4"

either = { version = "1.6", optional = true }
base64 = { version = "0.12.3", optional = true }
base64 = { version = "0.12.3" }
chrono = { version = "0.4", default-features = false, features = ["serde"] }
lru-cache = { version = "0.1", optional = true }
serde_json = { version = "1.0.48", optional = true, features = ["float_roundtrip"] }
serde_json = { version = "1.0.48", features = ["float_roundtrip"] }
native-tls = { version = "0.2", optional = true }
bit-vec = { version = "0.6.1", optional = true }
bytes = { version = "1.0", optional = true }
Expand Down
34 changes: 17 additions & 17 deletions quaint/src/ast/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub enum Compare<'a> {
/// without visitor transformation in between.
Raw(Box<Expression<'a>>, Cow<'a, str>, Box<Expression<'a>>),
/// All json related comparators
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
JsonCompare(JsonCompare<'a>),
/// `left` @@ to_tsquery(`value`)
#[cfg(feature = "postgresql")]
Expand Down Expand Up @@ -558,7 +558,7 @@ pub trait Comparable<'a> {
/// # Ok(())
/// # }
/// ```
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_contains<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>;
Expand All @@ -578,7 +578,7 @@ pub trait Comparable<'a> {
/// # Ok(())
/// # }
/// ```
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_contains<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>;
Expand Down Expand Up @@ -608,7 +608,7 @@ pub trait Comparable<'a> {
/// # Ok(())
/// # }
/// ```
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_begins_with<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>;
Expand Down Expand Up @@ -638,7 +638,7 @@ pub trait Comparable<'a> {
/// # Ok(())
/// # }
/// ```
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_begins_with<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>;
Expand Down Expand Up @@ -666,7 +666,7 @@ pub trait Comparable<'a> {
/// # Ok(())
/// # }
/// ```
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_ends_into<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>;
Expand Down Expand Up @@ -694,7 +694,7 @@ pub trait Comparable<'a> {
/// # Ok(())
/// # }
/// ```
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_ends_into<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>;
Expand All @@ -713,7 +713,7 @@ pub trait Comparable<'a> {
/// # Ok(())
/// # }
/// ```
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_type_equals<T>(self, json_type: T) -> Compare<'a>
where
T: Into<JsonType<'a>>;
Expand All @@ -732,7 +732,7 @@ pub trait Comparable<'a> {
/// # Ok(())
/// # }
/// ```
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_type_not_equals<T>(self, json_type: T) -> Compare<'a>
where
T: Into<JsonType<'a>>;
Expand Down Expand Up @@ -977,7 +977,7 @@ where
left.compare_raw(raw_comparator.into(), right)
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_contains<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -988,7 +988,7 @@ where
val.json_array_contains(item)
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_contains<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -999,7 +999,7 @@ where
val.json_array_not_contains(item)
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_begins_with<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -1010,7 +1010,7 @@ where
val.json_array_begins_with(item)
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_begins_with<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -1021,7 +1021,7 @@ where
val.json_array_not_begins_with(item)
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_ends_into<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -1032,7 +1032,7 @@ where
val.json_array_ends_into(item)
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_ends_into<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -1043,7 +1043,7 @@ where
val.json_array_not_ends_into(item)
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_type_equals<T>(self, json_type: T) -> Compare<'a>
where
T: Into<JsonType<'a>>,
Expand All @@ -1054,7 +1054,7 @@ where
val.json_type_equals(json_type)
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_type_not_equals<T>(self, json_type: T) -> Compare<'a>
where
T: Into<JsonType<'a>>,
Expand Down
34 changes: 15 additions & 19 deletions quaint/src/ast/expression.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
use super::compare::{JsonCompare, JsonType};
use crate::ast::*;
use query::SelectQuery;
Expand Down Expand Up @@ -43,38 +43,34 @@ impl<'a> Expression<'a> {
}
}

#[cfg(feature = "json")]
pub(crate) fn is_json_expr(&self) -> bool {
match &self.kind {
#[cfg(feature = "json")]
ExpressionKind::Parameterized(Value::Json(_)) => true,
#[cfg(feature = "json")]

ExpressionKind::Value(expr) => expr.is_json_value(),
#[cfg(feature = "json")]

ExpressionKind::Function(fun) => fun.returns_json(),
_ => false,
}
}

#[allow(dead_code)]
#[cfg(feature = "json")]

pub(crate) fn is_json_value(&self) -> bool {
match &self.kind {
#[cfg(feature = "json")]
ExpressionKind::Parameterized(Value::Json(_)) => true,
#[cfg(feature = "json")]

ExpressionKind::Value(expr) => expr.is_json_value(),
_ => false,
}
}

#[allow(dead_code)]
#[cfg(feature = "json")]

pub(crate) fn into_json_value(self) -> Option<serde_json::Value> {
match self.kind {
#[cfg(feature = "json")]
ExpressionKind::Parameterized(Value::Json(json_val)) => json_val,
#[cfg(feature = "json")]

ExpressionKind::Value(expr) => expr.into_json_value(),
_ => None,
}
Expand Down Expand Up @@ -427,23 +423,23 @@ impl<'a> Comparable<'a> for Expression<'a> {
Compare::Raw(Box::new(self), raw_comparator.into(), Box::new(right.into()))
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_contains<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
{
Compare::JsonCompare(JsonCompare::ArrayContains(Box::new(self), Box::new(item.into())))
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_contains<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
{
Compare::JsonCompare(JsonCompare::ArrayNotContains(Box::new(self), Box::new(item.into())))
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_begins_with<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -453,7 +449,7 @@ impl<'a> Comparable<'a> for Expression<'a> {
Compare::Equals(Box::new(array_starts_with), Box::new(item.into()))
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_begins_with<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -463,7 +459,7 @@ impl<'a> Comparable<'a> for Expression<'a> {
Compare::NotEquals(Box::new(array_starts_with), Box::new(item.into()))
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_ends_into<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -473,7 +469,7 @@ impl<'a> Comparable<'a> for Expression<'a> {
Compare::Equals(Box::new(array_ends_into), Box::new(item.into()))
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_array_not_ends_into<T>(self, item: T) -> Compare<'a>
where
T: Into<Expression<'a>>,
Expand All @@ -483,15 +479,15 @@ impl<'a> Comparable<'a> for Expression<'a> {
Compare::NotEquals(Box::new(array_ends_into), Box::new(item.into()))
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_type_equals<T>(self, json_type: T) -> Compare<'a>
where
T: Into<JsonType<'a>>,
{
Compare::JsonCompare(JsonCompare::TypeEquals(Box::new(self), json_type.into()))
}

#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))]
#[cfg(any(feature = "postgresql", feature = "mysql"))]
fn json_type_not_equals<T>(self, json_type: T) -> Compare<'a>
where
T: Into<JsonType<'a>>,
Expand Down
Loading

0 comments on commit 25a7735

Please sign in to comment.