diff --git a/.github/workflows/quaint.yml b/.github/workflows/quaint.yml index 3ea87d7fcae0..d84590b951b4 100644 --- a/.github/workflows/quaint.yml +++ b/.github/workflows/quaint.yml @@ -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" diff --git a/Cargo.toml b/Cargo.toml index e464a500dcc9..77afa5ee21d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,7 +58,6 @@ features = [ "bigdecimal", "expose-drivers", "fmt-sql", - "json", "mssql", "mysql", "pooled", diff --git a/quaint/.github/workflows/test.yml b/quaint/.github/workflows/test.yml index 058c177a0bd4..998a1a71ca46 100644 --- a/quaint/.github/workflows/test.yml +++ b/quaint/.github/workflows/test.yml @@ -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" diff --git a/quaint/Cargo.toml b/quaint/Cargo.toml index 2ff5a69bd97a..90f0eacc1fd2 100644 --- a/quaint/Cargo.toml +++ b/quaint/Cargo.toml @@ -30,7 +30,6 @@ docs = [] expose-drivers = [] all = [ - "json", "mssql", "mysql", "pooled", @@ -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"] @@ -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 } diff --git a/quaint/src/ast/compare.rs b/quaint/src/ast/compare.rs index d92843a23557..9c7548303466 100644 --- a/quaint/src/ast/compare.rs +++ b/quaint/src/ast/compare.rs @@ -37,7 +37,7 @@ pub enum Compare<'a> { /// without visitor transformation in between. Raw(Box>, Cow<'a, str>, Box>), /// 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")] @@ -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(self, item: T) -> Compare<'a> where T: Into>; @@ -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(self, item: T) -> Compare<'a> where T: Into>; @@ -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(self, item: T) -> Compare<'a> where T: Into>; @@ -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(self, item: T) -> Compare<'a> where T: Into>; @@ -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(self, item: T) -> Compare<'a> where T: Into>; @@ -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(self, item: T) -> Compare<'a> where T: Into>; @@ -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(self, json_type: T) -> Compare<'a> where T: Into>; @@ -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(self, json_type: T) -> Compare<'a> where T: Into>; @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, json_type: T) -> Compare<'a> where T: Into>, @@ -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(self, json_type: T) -> Compare<'a> where T: Into>, diff --git a/quaint/src/ast/expression.rs b/quaint/src/ast/expression.rs index b3993abc523b..7e5912d1e027 100644 --- a/quaint/src/ast/expression.rs +++ b/quaint/src/ast/expression.rs @@ -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; @@ -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 { 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, } @@ -427,7 +423,7 @@ 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(self, item: T) -> Compare<'a> where T: Into>, @@ -435,7 +431,7 @@ impl<'a> Comparable<'a> for 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(self, item: T) -> Compare<'a> where T: Into>, @@ -443,7 +439,7 @@ impl<'a> Comparable<'a> for 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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -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(self, item: T) -> Compare<'a> where T: Into>, @@ -483,7 +479,7 @@ 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(self, json_type: T) -> Compare<'a> where T: Into>, @@ -491,7 +487,7 @@ impl<'a> Comparable<'a> for Expression<'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(self, json_type: T) -> Compare<'a> where T: Into>, diff --git a/quaint/src/ast/function.rs b/quaint/src/ast/function.rs index 123b95566b30..5b6373795485 100644 --- a/quaint/src/ast/function.rs +++ b/quaint/src/ast/function.rs @@ -3,17 +3,17 @@ mod average; mod coalesce; mod concat; mod count; -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] mod json_extract; -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] mod json_extract_array; -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] mod json_unquote; mod lower; mod maximum; mod minimum; mod row_number; -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] mod row_to_json; #[cfg(any(feature = "postgresql", feature = "mysql"))] mod search; @@ -28,19 +28,19 @@ pub use average::*; pub use coalesce::*; pub use concat::*; pub use count::*; -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] pub use json_extract::*; -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] pub(crate) use json_extract_array::*; -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] pub use json_unquote::*; pub use lower::*; pub use maximum::*; pub use minimum::*; pub use row_number::*; -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] pub use row_to_json::*; -#[cfg(any(feature = "postgresql", feature = "mysql"))] +#[cfg(feature = "mysql")] pub use search::*; pub use sum::*; pub use upper::*; @@ -61,13 +61,13 @@ pub struct Function<'a> { impl<'a> Function<'a> { pub fn returns_json(&self) -> bool { match self.typ_ { - #[cfg(all(feature = "json", feature = "postgresql"))] + #[cfg(feature = "postgresql")] FunctionType::RowToJson(_) => true, - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(feature = "mysql")] FunctionType::JsonExtract(_) => true, - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] FunctionType::JsonExtractLastArrayElem(_) => true, - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] FunctionType::JsonExtractFirstArrayElem(_) => true, _ => false, } @@ -77,7 +77,7 @@ impl<'a> Function<'a> { /// A database function type #[derive(Debug, Clone, PartialEq)] pub(crate) enum FunctionType<'a> { - #[cfg(all(feature = "json", feature = "postgresql"))] + #[cfg(feature = "postgresql")] RowToJson(RowToJson<'a>), RowNumber(RowNumber<'a>), Count(Count<'a>), @@ -90,13 +90,13 @@ pub(crate) enum FunctionType<'a> { Maximum(Maximum<'a>), Coalesce(Coalesce<'a>), Concat(Concat<'a>), - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] JsonExtract(JsonExtract<'a>), - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] JsonExtractLastArrayElem(JsonExtractLastArrayElem<'a>), - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] JsonExtractFirstArrayElem(JsonExtractFirstArrayElem<'a>), - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] JsonUnquote(JsonUnquote<'a>), #[cfg(any(feature = "postgresql", feature = "mysql"))] TextSearch(TextSearch<'a>), @@ -122,19 +122,19 @@ impl<'a> Aliasable<'a> for Function<'a> { } } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] function!(RowToJson); -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] function!(JsonExtract); -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] function!(JsonExtractLastArrayElem); -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] function!(JsonExtractFirstArrayElem); -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] function!(JsonUnquote); #[cfg(any(feature = "postgresql", feature = "mysql"))] diff --git a/quaint/src/ast/function/row_to_json.rs b/quaint/src/ast/function/row_to_json.rs index 7ce8e0c98cc6..1093431e7412 100644 --- a/quaint/src/ast/function/row_to_json.rs +++ b/quaint/src/ast/function/row_to_json.rs @@ -3,7 +3,7 @@ use crate::ast::Table; #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "docs", doc(cfg(feature = "postgresql")))] -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] /// A representation of the `ROW_TO_JSON` function in the database. /// Only for `Postgresql` pub struct RowToJson<'a> { @@ -40,7 +40,7 @@ pub struct RowToJson<'a> { /// # } /// ``` #[cfg_attr(feature = "docs", doc(cfg(feature = "postgresql")))] -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] pub fn row_to_json<'a, T>(expr: T, pretty_print: bool) -> Function<'a> where T: Into>, diff --git a/quaint/src/ast/row.rs b/quaint/src/ast/row.rs index 3022b9127758..e556cee966af 100644 --- a/quaint/src/ast/row.rs +++ b/quaint/src/ast/row.rs @@ -1,4 +1,4 @@ -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] use super::compare::JsonType; use crate::ast::{Comparable, Compare, Expression}; use std::borrow::Cow; @@ -283,7 +283,7 @@ impl<'a> Comparable<'a> for Row<'a> { value.compare_raw(raw_comparator, right) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn json_array_contains(self, item: T) -> Compare<'a> where T: Into>, @@ -293,7 +293,7 @@ impl<'a> Comparable<'a> for Row<'a> { value.json_array_contains(item) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn json_array_not_contains(self, item: T) -> Compare<'a> where T: Into>, @@ -303,7 +303,7 @@ impl<'a> Comparable<'a> for Row<'a> { value.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(self, item: T) -> Compare<'a> where T: Into>, @@ -313,7 +313,7 @@ impl<'a> Comparable<'a> for Row<'a> { value.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(self, item: T) -> Compare<'a> where T: Into>, @@ -323,7 +323,7 @@ impl<'a> Comparable<'a> for Row<'a> { value.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(self, item: T) -> Compare<'a> where T: Into>, @@ -333,7 +333,7 @@ impl<'a> Comparable<'a> for Row<'a> { value.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(self, item: T) -> Compare<'a> where T: Into>, @@ -343,7 +343,7 @@ impl<'a> Comparable<'a> for Row<'a> { value.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(self, json_type: T) -> Compare<'a> where T: Into>, @@ -353,7 +353,7 @@ impl<'a> Comparable<'a> for Row<'a> { value.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(self, json_type: T) -> Compare<'a> where T: Into>, diff --git a/quaint/src/ast/values.rs b/quaint/src/ast/values.rs index 3daf6655bf6d..874e6f4cb0b7 100644 --- a/quaint/src/ast/values.rs +++ b/quaint/src/ast/values.rs @@ -4,7 +4,6 @@ use crate::error::{Error, ErrorKind}; #[cfg(feature = "bigdecimal")] use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive}; use chrono::{DateTime, NaiveDate, NaiveTime, Utc}; -#[cfg(feature = "json")] use serde_json::{Number, Value as JsonValue}; use std::{ borrow::{Borrow, Cow}, @@ -64,8 +63,6 @@ pub enum Value<'a> { #[cfg(feature = "bigdecimal")] #[cfg_attr(feature = "docs", doc(cfg(feature = "bigdecimal")))] Numeric(Option), - #[cfg(feature = "json")] - #[cfg_attr(feature = "docs", doc(cfg(feature = "json")))] /// A JSON value. Json(Option), /// A XML value. @@ -128,7 +125,6 @@ impl<'a> fmt::Display for Value<'a> { Value::Xml(val) => val.as_ref().map(|v| write!(f, "{v}")), #[cfg(feature = "bigdecimal")] Value::Numeric(val) => val.as_ref().map(|v| write!(f, "{v}")), - #[cfg(feature = "json")] Value::Json(val) => val.as_ref().map(|v| write!(f, "{v}")), #[cfg(feature = "uuid")] Value::Uuid(val) => val.map(|v| write!(f, "\"{v}\"")), @@ -144,8 +140,6 @@ impl<'a> fmt::Display for Value<'a> { } } -#[cfg(feature = "json")] -#[cfg_attr(feature = "docs", doc(cfg(feature = "json")))] impl<'a> From> for serde_json::Value { fn from(pv: Value<'a>) -> Self { let res = match pv { @@ -176,7 +170,6 @@ impl<'a> From> for serde_json::Value { } #[cfg(feature = "bigdecimal")] Value::Numeric(d) => d.map(|d| serde_json::to_value(d.to_f64().unwrap()).unwrap()), - #[cfg(feature = "json")] Value::Json(v) => v, #[cfg(feature = "uuid")] Value::Uuid(u) => u.map(|u| serde_json::Value::String(u.hyphenated().to_string())), @@ -306,8 +299,6 @@ impl<'a> Value<'a> { } /// Creates a new JSON value. - #[cfg(feature = "json")] - #[cfg_attr(feature = "docs", doc(cfg(feature = "json")))] pub const fn json(value: serde_json::Value) -> Self { Value::Json(Some(value)) } @@ -341,7 +332,6 @@ impl<'a> Value<'a> { Value::DateTime(dt) => dt.is_none(), Value::Date(d) => d.is_none(), Value::Time(t) => t.is_none(), - #[cfg(feature = "json")] Value::Json(json) => json.is_none(), } } @@ -581,15 +571,11 @@ impl<'a> Value<'a> { } /// `true` if the `Value` is a JSON value. - #[cfg(feature = "json")] - #[cfg_attr(feature = "docs", doc(cfg(feature = "json")))] pub const fn is_json(&self) -> bool { matches!(self, Value::Json(_)) } /// Returns a reference to a JSON Value if of Json type, otherwise `None`. - #[cfg(feature = "json")] - #[cfg_attr(feature = "docs", doc(cfg(feature = "json")))] pub const fn as_json(&self) -> Option<&serde_json::Value> { match self { Value::Json(Some(j)) => Some(j), @@ -598,8 +584,6 @@ impl<'a> Value<'a> { } /// Transforms to a JSON Value if of Json type, otherwise `None`. - #[cfg(feature = "json")] - #[cfg_attr(feature = "docs", doc(cfg(feature = "json")))] pub fn into_json(self) -> Option { match self { Value::Json(Some(j)) => Some(j), @@ -658,7 +642,6 @@ value!(val: chrono::NaiveTime, Time, val); value!(val: chrono::NaiveDate, Date, val); #[cfg(feature = "bigdecimal")] value!(val: BigDecimal, Numeric, val); -#[cfg(feature = "json")] value!(val: JsonValue, Json, val); #[cfg(feature = "uuid")] value!(val: Uuid, Uuid, val); diff --git a/quaint/src/connector/mssql/conversion.rs b/quaint/src/connector/mssql/conversion.rs index 862993e2e3eb..d80c0aa6b0dc 100644 --- a/quaint/src/connector/mssql/conversion.rs +++ b/quaint/src/connector/mssql/conversion.rs @@ -24,7 +24,6 @@ impl<'a> IntoSql<'a> for &'a Value<'a> { Value::Array(_) => panic!("Arrays are not supported on SQL Server."), #[cfg(feature = "bigdecimal")] Value::Numeric(val) => (*val).to_sql(), - #[cfg(feature = "json")] Value::Json(val) => val.as_ref().map(|val| serde_json::to_string(&val).unwrap()).into_sql(), #[cfg(feature = "uuid")] Value::Uuid(val) => val.into_sql(), diff --git a/quaint/src/connector/mysql/conversion.rs b/quaint/src/connector/mysql/conversion.rs index 18e1ce4cd431..41e08f5a4416 100644 --- a/quaint/src/connector/mysql/conversion.rs +++ b/quaint/src/connector/mysql/conversion.rs @@ -41,7 +41,6 @@ pub fn conv_params(params: &[Value<'_>]) -> crate::Result { } #[cfg(feature = "bigdecimal")] Value::Numeric(f) => f.as_ref().map(|f| my::Value::Bytes(f.to_string().as_bytes().to_vec())), - #[cfg(feature = "json")] Value::Json(s) => match s { Some(ref s) => { let json = serde_json::to_string(s)?; @@ -223,7 +222,6 @@ impl TakeRow for my::Row { let res = match value { // JSON is returned as bytes. - #[cfg(feature = "json")] my::Value::Bytes(b) if column.is_json() => { serde_json::from_slice(&b).map(Value::json).map_err(|_| { let msg = "Unable to convert bytes to JSON"; @@ -319,7 +317,6 @@ impl TakeRow for my::Row { t if t.is_datetime() => Value::DateTime(None), t if t.is_time() => Value::Time(None), t if t.is_date() => Value::Date(None), - #[cfg(feature = "json")] t if t.is_json() => Value::Json(None), typ => { let msg = format!("Value of type {typ:?} is not supported with the current configuration"); diff --git a/quaint/src/connector/postgres/conversion.rs b/quaint/src/connector/postgres/conversion.rs index 181557c2e48d..8ceddcd3d704 100644 --- a/quaint/src/connector/postgres/conversion.rs +++ b/quaint/src/connector/postgres/conversion.rs @@ -51,7 +51,6 @@ pub(crate) fn params_to_types(params: &[Value<'_>]) -> Vec { Value::Char(_) => PostgresType::CHAR, #[cfg(feature = "bigdecimal")] Value::Numeric(_) => PostgresType::NUMERIC, - #[cfg(feature = "json")] Value::Json(_) => PostgresType::JSONB, Value::Xml(_) => PostgresType::XML, #[cfg(feature = "uuid")] @@ -90,7 +89,6 @@ pub(crate) fn params_to_types(params: &[Value<'_>]) -> Vec { Value::Char(_) => PostgresType::CHAR_ARRAY, #[cfg(feature = "bigdecimal")] Value::Numeric(_) => PostgresType::NUMERIC_ARRAY, - #[cfg(feature = "json")] Value::Json(_) => PostgresType::JSONB_ARRAY, Value::Xml(_) => PostgresType::XML_ARRAY, #[cfg(feature = "uuid")] @@ -287,7 +285,6 @@ impl GetRow for PostgresRow { } None => Value::Array(None), }, - #[cfg(feature = "json")] PostgresType::JSON | PostgresType::JSONB => Value::Json(row.try_get(i)?), PostgresType::INT2_ARRAY => match row.try_get(i)? { Some(val) => { @@ -433,7 +430,6 @@ impl GetRow for PostgresRow { } None => Value::Array(None), }, - #[cfg(feature = "json")] PostgresType::JSON_ARRAY => match row.try_get(i)? { Some(val) => { let val: Vec> = val; @@ -443,7 +439,6 @@ impl GetRow for PostgresRow { } None => Value::Array(None), }, - #[cfg(feature = "json")] PostgresType::JSONB_ARRAY => match row.try_get(i)? { Some(val) => { let val: Vec> = val; @@ -822,7 +817,6 @@ impl<'a> ToSql for Value<'a> { parsed_ip_addr.to_sql(ty, out) }) } - #[cfg(feature = "json")] (Value::Text(string), &PostgresType::JSON) | (Value::Text(string), &PostgresType::JSONB) => string .as_ref() .map(|string| serde_json::from_str::(string)?.to_sql(ty, out)), @@ -861,7 +855,6 @@ impl<'a> ToSql for Value<'a> { return Err(Error::builder(kind).build().into()); } - #[cfg(feature = "json")] (Value::Json(value), _) => value.as_ref().map(|value| value.to_sql(ty, out)), (Value::Xml(value), _) => value.as_ref().map(|value| value.to_sql(ty, out)), #[cfg(feature = "uuid")] diff --git a/quaint/src/connector/result_set.rs b/quaint/src/connector/result_set.rs index dedc49d23ff9..b98d252a0579 100644 --- a/quaint/src/connector/result_set.rs +++ b/quaint/src/connector/result_set.rs @@ -5,10 +5,8 @@ pub use index::*; pub use result_row::*; use crate::{ast::Value, error::*}; -use std::sync::Arc; - -#[cfg(feature = "json")] use serde_json::Map; +use std::sync::Arc; /// Encapsulates a set of results and their respective column names. #[derive(Debug, Default)] @@ -108,8 +106,6 @@ impl Iterator for ResultSetIterator { } } -#[cfg(feature = "json")] -#[cfg_attr(feature = "docs", doc(cfg(feature = "json")))] impl From for serde_json::Value { fn from(result_set: ResultSet) -> Self { let columns: Vec = result_set.columns().iter().map(ToString::to_string).collect(); diff --git a/quaint/src/connector/sqlite/conversion.rs b/quaint/src/connector/sqlite/conversion.rs index 23f20edbabe0..ab62992e7a67 100644 --- a/quaint/src/connector/sqlite/conversion.rs +++ b/quaint/src/connector/sqlite/conversion.rs @@ -268,7 +268,6 @@ impl<'a> ToSql for Value<'a> { Value::Numeric(d) => d .as_ref() .map(|d| ToSqlOutput::from(d.to_string().parse::().expect("BigDecimal is not a f64."))), - #[cfg(feature = "json")] Value::Json(value) => value.as_ref().map(|value| { let stringified = serde_json::to_string(value) .map_err(|err| RusqlError::ToSqlConversionFailure(Box::new(err))) diff --git a/quaint/src/error.rs b/quaint/src/error.rs index 73f88dc90b30..5ca712c7be71 100644 --- a/quaint/src/error.rs +++ b/quaint/src/error.rs @@ -326,8 +326,6 @@ impl From for Error { } } -#[cfg(feature = "json")] -#[cfg_attr(feature = "docs", doc(cfg(feature = "json")))] impl From for Error { fn from(_: serde_json::Error) -> Self { Self::builder(ErrorKind::conversion("Malformed JSON data.")).build() diff --git a/quaint/src/serde.rs b/quaint/src/serde.rs index 7bd5d10f72c0..85b605aec034 100644 --- a/quaint/src/serde.rs +++ b/quaint/src/serde.rs @@ -140,14 +140,12 @@ impl<'de> Deserializer<'de> for ValueDeserializer<'de> { #[cfg(feature = "uuid")] Value::Uuid(None) => visitor.visit_none(), - #[cfg(feature = "json")] Value::Json(Some(value)) => { let de = value.into_deserializer(); de.deserialize_any(visitor) .map_err(|err| serde::de::value::Error::custom(format!("Error deserializing JSON value: {err}"))) } - #[cfg(feature = "json")] Value::Json(None) => visitor.visit_none(), Value::Xml(Some(s)) => visitor.visit_string(s.into_owned()), diff --git a/quaint/src/tests/query.rs b/quaint/src/tests/query.rs index 26a0162bb8f6..dc286307cf1d 100644 --- a/quaint/src/tests/query.rs +++ b/quaint/src/tests/query.rs @@ -1,7 +1,7 @@ mod error; use super::test_api::*; -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] use crate::ast::JsonPath; use crate::{ connector::{IsolationLevel, Queryable, TransactionCapable}, @@ -1412,7 +1412,6 @@ async fn unsigned_integers_are_handled(api: &mut dyn TestApi) -> crate::Result<( Ok(()) } -#[cfg(feature = "json")] #[test_each_connector(tags("mysql", "postgresql"))] async fn json_filtering_works(api: &mut dyn TestApi) -> crate::Result<()> { let json_type = match api.system() { @@ -1691,7 +1690,7 @@ async fn enum_values(api: &mut dyn TestApi) -> crate::Result<()> { } #[test_each_connector(tags("postgresql"))] -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] async fn row_to_json_normal(api: &mut dyn TestApi) -> crate::Result<()> { let cte = Select::default() .value(val!("hello_world").alias("toto")) @@ -1710,7 +1709,7 @@ async fn row_to_json_normal(api: &mut dyn TestApi) -> crate::Result<()> { } #[test_each_connector(tags("postgresql"))] -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] async fn row_to_json_pretty(api: &mut dyn TestApi) -> crate::Result<()> { let cte = Select::default() .value(val!("hello_world").alias("toto")) @@ -2067,7 +2066,6 @@ async fn coalesce_fun(api: &mut dyn TestApi) -> crate::Result<()> { Ok(()) } -#[cfg(feature = "json")] fn value_into_json(value: &Value) -> Option { match value.clone() { // MariaDB returns JSON as text @@ -2082,7 +2080,7 @@ fn value_into_json(value: &Value) -> Option { } } -#[cfg(all(feature = "json", feature = "mysql"))] +#[cfg(feature = "mysql")] #[test_each_connector(tags("mysql"))] async fn json_extract_path_fun(api: &mut dyn TestApi) -> crate::Result<()> { let table = api @@ -2133,7 +2131,7 @@ async fn json_extract_path_fun(api: &mut dyn TestApi) -> crate::Result<()> { Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] async fn json_extract_array_path_postgres(api: &mut dyn TestApi, json_type: &str) -> crate::Result<()> { let table = api .create_temp_table(&format!("{}, obj {}", api.autogen_id("id"), json_type)) @@ -2192,7 +2190,7 @@ async fn json_extract_array_path_postgres(api: &mut dyn TestApi, json_type: &str Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_extract_array_path_fun_on_jsonb(api: &mut dyn TestApi) -> crate::Result<()> { json_extract_array_path_postgres(api, "jsonb").await?; @@ -2200,7 +2198,7 @@ async fn json_extract_array_path_fun_on_jsonb(api: &mut dyn TestApi) -> crate::R Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_extract_array_path_fun_on_json(api: &mut dyn TestApi) -> crate::Result<()> { json_extract_array_path_postgres(api, "json").await?; @@ -2208,7 +2206,7 @@ async fn json_extract_array_path_fun_on_json(api: &mut dyn TestApi) -> crate::Re Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] async fn json_array_contains(api: &mut dyn TestApi, json_type: &str) -> crate::Result<()> { let table = api .create_temp_table(&format!("{}, obj {}", api.autogen_id("id"), json_type)) @@ -2287,7 +2285,7 @@ async fn json_array_contains(api: &mut dyn TestApi, json_type: &str) -> crate::R Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_contains_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Result<()> { json_array_contains(api, "jsonb").await?; @@ -2295,7 +2293,7 @@ async fn json_array_contains_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Resul Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_contains_fun_pg_json(api: &mut dyn TestApi) -> crate::Result<()> { json_array_contains(api, "json").await?; @@ -2303,7 +2301,7 @@ async fn json_array_contains_fun_pg_json(api: &mut dyn TestApi) -> crate::Result Ok(()) } -#[cfg(all(feature = "json", feature = "mysql"))] +#[cfg(feature = "mysql")] #[test_each_connector(tags("mysql"))] async fn json_array_contains_fun(api: &mut dyn TestApi) -> crate::Result<()> { json_array_contains(api, "json").await?; @@ -2311,7 +2309,7 @@ async fn json_array_contains_fun(api: &mut dyn TestApi) -> crate::Result<()> { Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] async fn json_array_not_contains(api: &mut dyn TestApi, json_type: &str) -> crate::Result<()> { let table = api .create_temp_table(&format!("{}, obj {}", api.autogen_id("id"), json_type)) @@ -2345,7 +2343,7 @@ async fn json_array_not_contains(api: &mut dyn TestApi, json_type: &str) -> crat Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_not_contains_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_contains(api, "jsonb").await?; @@ -2353,7 +2351,7 @@ async fn json_array_not_contains_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::R Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_not_contains_fun_pg_json(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_contains(api, "json").await?; @@ -2361,7 +2359,7 @@ async fn json_array_not_contains_fun_pg_json(api: &mut dyn TestApi) -> crate::Re Ok(()) } -#[cfg(all(feature = "json", feature = "mysql"))] +#[cfg(feature = "mysql")] #[test_each_connector(tags("mysql"))] async fn json_array_not_contains_fun(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_contains(api, "json").await?; @@ -2369,7 +2367,7 @@ async fn json_array_not_contains_fun(api: &mut dyn TestApi) -> crate::Result<()> Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] async fn json_array_begins_with(api: &mut dyn TestApi, json_type: &str) -> crate::Result<()> { let table = api .create_temp_table(&format!("{}, obj {}", api.autogen_id("id"), json_type)) @@ -2437,7 +2435,7 @@ async fn json_array_begins_with(api: &mut dyn TestApi, json_type: &str) -> crate Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_begins_with_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Result<()> { json_array_begins_with(api, "jsonb").await?; @@ -2445,7 +2443,7 @@ async fn json_array_begins_with_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Re Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_begins_with_fun_pg_json(api: &mut dyn TestApi) -> crate::Result<()> { json_array_begins_with(api, "json").await?; @@ -2453,7 +2451,7 @@ async fn json_array_begins_with_fun_pg_json(api: &mut dyn TestApi) -> crate::Res Ok(()) } -#[cfg(all(feature = "json", feature = "mysql"))] +#[cfg(feature = "mysql")] #[test_each_connector(tags("mysql"))] async fn json_array_begins_with_fun(api: &mut dyn TestApi) -> crate::Result<()> { json_array_begins_with(api, "json").await?; @@ -2461,7 +2459,7 @@ async fn json_array_begins_with_fun(api: &mut dyn TestApi) -> crate::Result<()> Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] async fn json_array_not_begins_with(api: &mut dyn TestApi, json_type: &str) -> crate::Result<()> { let table = api .create_temp_table(&format!("{}, obj {}", api.autogen_id("id"), json_type)) @@ -2496,7 +2494,7 @@ async fn json_array_not_begins_with(api: &mut dyn TestApi, json_type: &str) -> c Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_not_begins_with_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_begins_with(api, "jsonb").await?; @@ -2504,7 +2502,7 @@ async fn json_array_not_begins_with_fun_pg_jsonb(api: &mut dyn TestApi) -> crate Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_not_begins_with_fun_pg_json(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_begins_with(api, "json").await?; @@ -2512,7 +2510,7 @@ async fn json_array_not_begins_with_fun_pg_json(api: &mut dyn TestApi) -> crate: Ok(()) } -#[cfg(all(feature = "json", feature = "mysql"))] +#[cfg(feature = "mysql")] #[test_each_connector(tags("mysql"))] async fn json_array_not_begins_with_fun(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_begins_with(api, "json").await?; @@ -2520,7 +2518,7 @@ async fn json_array_not_begins_with_fun(api: &mut dyn TestApi) -> crate::Result< Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] async fn json_array_ends_into(api: &mut dyn TestApi, json_type: &str) -> crate::Result<()> { let table = api .create_temp_table(&format!("{}, obj {}", api.autogen_id("id"), json_type)) @@ -2589,7 +2587,7 @@ async fn json_array_ends_into(api: &mut dyn TestApi, json_type: &str) -> crate:: Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_ends_into_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Result<()> { json_array_ends_into(api, "jsonb").await?; @@ -2597,7 +2595,7 @@ async fn json_array_ends_into_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Resu Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_ends_into_fun_pg_json(api: &mut dyn TestApi) -> crate::Result<()> { json_array_ends_into(api, "json").await?; @@ -2605,7 +2603,7 @@ async fn json_array_ends_into_fun_pg_json(api: &mut dyn TestApi) -> crate::Resul Ok(()) } -#[cfg(all(feature = "json", feature = "mysql"))] +#[cfg(feature = "mysql")] #[test_each_connector(tags("mysql"))] async fn json_array_ends_into_fun(api: &mut dyn TestApi) -> crate::Result<()> { json_array_ends_into(api, "json").await?; @@ -2613,7 +2611,7 @@ async fn json_array_ends_into_fun(api: &mut dyn TestApi) -> crate::Result<()> { Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] async fn json_array_not_ends_into(api: &mut dyn TestApi, json_type: &str) -> crate::Result<()> { let table = api .create_temp_table(&format!("{}, obj {}", api.autogen_id("id"), json_type)) @@ -2649,7 +2647,7 @@ async fn json_array_not_ends_into(api: &mut dyn TestApi, json_type: &str) -> cra Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_not_ends_into_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_ends_into(api, "jsonb").await?; @@ -2657,7 +2655,7 @@ async fn json_array_not_ends_into_fun_pg_jsonb(api: &mut dyn TestApi) -> crate:: Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_array_not_ends_into_fun_pg_json(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_ends_into(api, "json").await?; @@ -2665,7 +2663,7 @@ async fn json_array_not_ends_into_fun_pg_json(api: &mut dyn TestApi) -> crate::R Ok(()) } -#[cfg(all(feature = "json", feature = "mysql"))] +#[cfg(feature = "mysql")] #[test_each_connector(tags("mysql"))] async fn json_array_not_ends_into_fun(api: &mut dyn TestApi) -> crate::Result<()> { json_array_not_ends_into(api, "json").await?; @@ -2673,7 +2671,7 @@ async fn json_array_not_ends_into_fun(api: &mut dyn TestApi) -> crate::Result<() Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] async fn json_gt_gte_lt_lte(api: &mut dyn TestApi, json_type: &str) -> crate::Result<()> { let table = api .create_temp_table(&format!("{}, json {}", api.autogen_id("id"), json_type)) @@ -2817,7 +2815,7 @@ async fn json_gt_gte_lt_lte(api: &mut dyn TestApi, json_type: &str) -> crate::Re Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_gt_gte_lt_lte_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Result<()> { json_gt_gte_lt_lte(api, "jsonb").await?; @@ -2825,7 +2823,7 @@ async fn json_gt_gte_lt_lte_fun_pg_jsonb(api: &mut dyn TestApi) -> crate::Result Ok(()) } -#[cfg(all(feature = "json", feature = "postgresql"))] +#[cfg(feature = "postgresql")] #[test_each_connector(tags("postgresql"))] async fn json_gt_gte_lt_lte_fun_pg_json(api: &mut dyn TestApi) -> crate::Result<()> { json_gt_gte_lt_lte(api, "json").await?; @@ -2833,7 +2831,7 @@ async fn json_gt_gte_lt_lte_fun_pg_json(api: &mut dyn TestApi) -> crate::Result< Ok(()) } -#[cfg(all(feature = "json", feature = "mysql"))] +#[cfg(feature = "mysql")] #[test_each_connector(tags("mysql"))] async fn json_gt_gte_lt_lte_fun(api: &mut dyn TestApi) -> crate::Result<()> { json_gt_gte_lt_lte(api, "json").await?; @@ -3116,7 +3114,6 @@ async fn query_raw_typed_date(api: &mut dyn TestApi) -> crate::Result<()> { Ok(()) } -#[cfg(feature = "json")] #[test_each_connector(tags("postgresql"))] async fn query_raw_typed_json(api: &mut dyn TestApi) -> crate::Result<()> { use serde_json::json; @@ -3395,7 +3392,7 @@ async fn any_in_expression(api: &mut dyn TestApi) -> crate::Result<()> { Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] #[test_each_connector(tags("postgresql", "mysql"))] async fn json_unquote_fun(api: &mut dyn TestApi) -> crate::Result<()> { let json_type = match api.system() { @@ -3433,7 +3430,7 @@ async fn json_unquote_fun(api: &mut dyn TestApi) -> crate::Result<()> { Ok(()) } -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] #[test_each_connector(tags("postgresql", "mysql"))] async fn json_col_equal_json_col(api: &mut dyn TestApi) -> crate::Result<()> { let json_type = match api.system() { diff --git a/quaint/src/tests/types/mysql.rs b/quaint/src/tests/types/mysql.rs index 57b3738f6bd4..b69d736d4a3c 100644 --- a/quaint/src/tests/types/mysql.rs +++ b/quaint/src/tests/types/mysql.rs @@ -208,7 +208,6 @@ test_type!(enum( Value::enum_variant("pollicle_dogs") )); -#[cfg(feature = "json")] test_type!(json( mysql, "json", diff --git a/quaint/src/tests/types/postgres.rs b/quaint/src/tests/types/postgres.rs index 954082a3c5d5..3ca40c822a77 100644 --- a/quaint/src/tests/types/postgres.rs +++ b/quaint/src/tests/types/postgres.rs @@ -260,7 +260,6 @@ test_type!(inet_array( ]) )); -#[cfg(feature = "json")] test_type!(json( postgresql, "json", @@ -268,7 +267,6 @@ test_type!(json( Value::json(serde_json::json!({"foo": "bar"})) )); -#[cfg(feature = "json")] test_type!(json_array( postgresql, "json[]", @@ -280,7 +278,6 @@ test_type!(json_array( ]) )); -#[cfg(feature = "json")] test_type!(jsonb( postgresql, "jsonb", @@ -288,7 +285,6 @@ test_type!(jsonb( Value::json(serde_json::json!({"foo": "bar"})) )); -#[cfg(feature = "json")] test_type!(jsonb_array( postgresql, "jsonb[]", diff --git a/quaint/src/visitor.rs b/quaint/src/visitor.rs index 9f4d9bcb5bcd..a77e86533174 100644 --- a/quaint/src/visitor.rs +++ b/quaint/src/visitor.rs @@ -121,22 +121,22 @@ pub trait Visitor<'a> { /// Visit a non-parameterized value. fn visit_raw_value(&mut self, value: Value<'a>) -> Result; - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract(&mut self, json_extract: JsonExtract<'a>) -> Result; - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_last_array_item(&mut self, extract: JsonExtractLastArrayElem<'a>) -> Result; - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_first_array_item(&mut self, extract: JsonExtractFirstArrayElem<'a>) -> Result; - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_array_contains(&mut self, left: Expression<'a>, right: Expression<'a>, not: bool) -> Result; - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_type_equals(&mut self, left: Expression<'a>, right: JsonType<'a>, not: bool) -> Result; - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_unquote(&mut self, json_unquote: JsonUnquote<'a>) -> Result; #[cfg(any(feature = "postgresql", feature = "mysql"))] @@ -915,7 +915,7 @@ pub trait Visitor<'a> { self.write(" ")?; self.visit_expression(*right) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] Compare::JsonCompare(json_compare) => match json_compare { JsonCompare::ArrayContains(left, right) => self.visit_json_array_contains(*left, *right, false), JsonCompare::ArrayNotContains(left, right) => self.visit_json_array_contains(*left, *right, true), @@ -997,7 +997,7 @@ pub trait Visitor<'a> { FunctionType::AggregateToString(agg) => { self.visit_aggregate_to_string(agg.value.as_ref().clone())?; } - #[cfg(all(feature = "json", feature = "postgresql"))] + #[cfg(feature = "postgresql")] FunctionType::RowToJson(row_to_json) => { self.write("ROW_TO_JSON")?; self.surround_with("(", ")", |ref mut s| s.visit_table(row_to_json.expr, false))? @@ -1029,19 +1029,19 @@ pub trait Visitor<'a> { self.write("COALESCE")?; self.surround_with("(", ")", |s| s.visit_columns(coalesce.exprs))?; } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] FunctionType::JsonExtract(json_extract) => { self.visit_json_extract(json_extract)?; } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] FunctionType::JsonExtractFirstArrayElem(extract) => { self.visit_json_extract_first_array_item(extract)?; } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] FunctionType::JsonExtractLastArrayElem(extract) => { self.visit_json_extract_last_array_item(extract)?; } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] FunctionType::JsonUnquote(unquote) => { self.visit_json_unquote(unquote)?; } diff --git a/quaint/src/visitor/mssql.rs b/quaint/src/visitor/mssql.rs index 0353684a6cd3..a5975e6249fa 100644 --- a/quaint/src/visitor/mssql.rs +++ b/quaint/src/visitor/mssql.rs @@ -1,5 +1,5 @@ use super::Visitor; -#[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] +#[cfg(any(feature = "postgresql", feature = "mysql"))] use crate::prelude::{JsonExtract, JsonType, JsonUnquote}; use crate::{ ast::{ @@ -339,7 +339,7 @@ impl<'a> Visitor<'a> for Mssql<'a> { return Err(builder.build()); } - #[cfg(feature = "json")] + Value::Json(j) => j.map(|j| self.write(format!("'{}'", serde_json::to_string(&j).unwrap()))), #[cfg(feature = "bigdecimal")] Value::Numeric(r) => r.map(|r| self.write(r)), @@ -633,12 +633,12 @@ impl<'a> Visitor<'a> for Mssql<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract(&mut self, _json_extract: JsonExtract<'a>) -> visitor::Result { unimplemented!("JSON filtering is not yet supported on MSSQL") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_array_contains( &mut self, _left: Expression<'a>, @@ -648,12 +648,12 @@ impl<'a> Visitor<'a> for Mssql<'a> { unimplemented!("JSON filtering is not yet supported on MSSQL") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_type_equals(&mut self, _left: Expression<'a>, _json_type: JsonType, _not: bool) -> visitor::Result { unimplemented!("JSON_TYPE is not yet supported on MSSQL") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_unquote(&mut self, _json_unquote: JsonUnquote<'a>) -> visitor::Result { unimplemented!("JSON filtering is not yet supported on MSSQL") } @@ -681,7 +681,7 @@ impl<'a> Visitor<'a> for Mssql<'a> { unimplemented!("Full-text search is not yet supported on MSSQL") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_last_array_item( &mut self, _extract: crate::prelude::JsonExtractLastArrayElem<'a>, @@ -689,7 +689,7 @@ impl<'a> Visitor<'a> for Mssql<'a> { unimplemented!("JSON filtering is not yet supported on MSSQL") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_first_array_item( &mut self, _extract: crate::prelude::JsonExtractFirstArrayElem<'a>, @@ -1245,7 +1245,7 @@ mod tests { } #[test] - #[cfg(feature = "json")] + fn test_raw_json() { let (sql, params) = Mssql::build(Select::default().value(serde_json::json!({ "foo": "bar" }).raw())).unwrap(); assert_eq!("SELECT '{\"foo\":\"bar\"}'", sql); diff --git a/quaint/src/visitor/mysql.rs b/quaint/src/visitor/mysql.rs index fc23fd8ecf64..bbe4591575ef 100644 --- a/quaint/src/visitor/mysql.rs +++ b/quaint/src/visitor/mysql.rs @@ -34,7 +34,6 @@ impl<'a> Mysql<'a> { } fn visit_numeric_comparison(&mut self, left: Expression<'a>, right: Expression<'a>, sign: &str) -> visitor::Result { - #[cfg(feature = "json")] fn json_to_quaint_value<'a>(json: serde_json::Value) -> crate::Result> { match json { serde_json::Value::String(str) => Ok(Value::text(str)), @@ -61,7 +60,6 @@ impl<'a> Mysql<'a> { } match (left, right) { - #[cfg(feature = "json")] (left, right) if left.is_json_value() && right.is_fun_retuning_json() => { let quaint_value = json_to_quaint_value(left.into_json_value().unwrap())?; @@ -69,7 +67,7 @@ impl<'a> Mysql<'a> { self.write(format!(" {sign} "))?; self.visit_expression(right)?; } - #[cfg(feature = "json")] + (left, right) if left.is_fun_retuning_json() && right.is_json_value() => { let quaint_value = json_to_quaint_value(right.into_json_value().unwrap())?; @@ -153,7 +151,7 @@ impl<'a> Visitor<'a> for Mysql<'a> { } #[cfg(feature = "bigdecimal")] Value::Numeric(r) => r.map(|r| self.write(r)), - #[cfg(feature = "json")] + Value::Json(j) => match j { Some(ref j) => { let s = serde_json::to_string(&j)?; @@ -318,7 +316,6 @@ impl<'a> Visitor<'a> for Mysql<'a> { } fn visit_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> visitor::Result { - #[cfg(feature = "json")] { if right.is_json_expr() || left.is_json_expr() { self.surround_with("(", ")", |ref mut s| { @@ -342,15 +339,9 @@ impl<'a> Visitor<'a> for Mysql<'a> { self.visit_regular_equality_comparison(left, right) } } - - #[cfg(not(feature = "json"))] - { - self.visit_regular_equality_comparison(left, right) - } } fn visit_not_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> visitor::Result { - #[cfg(feature = "json")] { if right.is_json_expr() || left.is_json_expr() { self.surround_with("(", ")", |ref mut s| { @@ -374,14 +365,9 @@ impl<'a> Visitor<'a> for Mysql<'a> { self.visit_regular_difference_comparison(left, right) } } - - #[cfg(not(feature = "json"))] - { - self.visit_regular_difference_comparison(left, right) - } } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract(&mut self, json_extract: JsonExtract<'a>) -> visitor::Result { if json_extract.extract_as_string { self.write("JSON_UNQUOTE(")?; @@ -406,7 +392,7 @@ impl<'a> Visitor<'a> for Mysql<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_array_contains(&mut self, left: Expression<'a>, right: Expression<'a>, not: bool) -> visitor::Result { self.write("JSON_CONTAINS(")?; self.visit_expression(left)?; @@ -421,7 +407,7 @@ impl<'a> Visitor<'a> for Mysql<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_type_equals(&mut self, left: Expression<'a>, json_type: JsonType<'a>, not: bool) -> visitor::Result { self.write("(")?; self.write("JSON_TYPE")?; @@ -533,7 +519,7 @@ impl<'a> Visitor<'a> for Mysql<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_last_array_item(&mut self, extract: JsonExtractLastArrayElem<'a>) -> visitor::Result { self.write("JSON_EXTRACT(")?; self.visit_expression(*extract.expr.clone())?; @@ -546,7 +532,7 @@ impl<'a> Visitor<'a> for Mysql<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_first_array_item(&mut self, extract: JsonExtractFirstArrayElem<'a>) -> visitor::Result { self.write("JSON_EXTRACT(")?; self.visit_expression(*extract.expr)?; @@ -557,7 +543,7 @@ impl<'a> Visitor<'a> for Mysql<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_unquote(&mut self, json_unquote: JsonUnquote<'a>) -> visitor::Result { self.write("JSON_UNQUOTE(")?; self.visit_expression(*json_unquote.expr)?; @@ -724,7 +710,6 @@ mod tests { ); } - #[cfg(feature = "json")] #[test] fn equality_with_a_json_value() { let expected = expected_values( @@ -739,7 +724,6 @@ mod tests { assert_eq!(expected.1, params); } - #[cfg(feature = "json")] #[test] fn difference_with_a_json_value() { let expected = expected_values( @@ -856,7 +840,7 @@ mod tests { } #[test] - #[cfg(feature = "json")] + fn test_raw_json() { let (sql, params) = Mysql::build(Select::default().value(serde_json::json!({ "foo": "bar" }).raw())).unwrap(); assert_eq!("SELECT CONVERT('{\"foo\":\"bar\"}', JSON)", sql); @@ -911,7 +895,7 @@ mod tests { } #[test] - #[cfg(feature = "json")] + fn test_json_negation() { let conditions = ConditionTree::not("json".equals(Value::Json(Some(serde_json::Value::Null)))); let (sql, _) = Mysql::build(Select::from_table("test").so_that(conditions)).unwrap(); @@ -923,7 +907,7 @@ mod tests { } #[test] - #[cfg(feature = "json")] + fn test_json_not_negation() { let conditions = ConditionTree::not("json".not_equals(Value::Json(Some(serde_json::Value::Null)))); let (sql, _) = Mysql::build(Select::from_table("test").so_that(conditions)).unwrap(); diff --git a/quaint/src/visitor/postgres.rs b/quaint/src/visitor/postgres.rs index fa6511ea3a40..f18114ba5888 100644 --- a/quaint/src/visitor/postgres.rs +++ b/quaint/src/visitor/postgres.rs @@ -105,7 +105,7 @@ impl<'a> Visitor<'a> for Postgres<'a> { Ok(()) }) }), - #[cfg(feature = "json")] + Value::Json(j) => j.map(|j| self.write(format!("'{}'", serde_json::to_string(&j).unwrap()))), #[cfg(feature = "bigdecimal")] Value::Numeric(r) => r.map(|r| self.write(r)), @@ -226,14 +226,12 @@ impl<'a> Visitor<'a> for Postgres<'a> { fn visit_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> visitor::Result { // LHS must be cast to json/xml-text if the right is a json/xml-text value and vice versa. let right_cast = match left { - #[cfg(feature = "json")] _ if left.is_json_value() => "::jsonb", _ if left.is_xml_value() => "::text", _ => "", }; let left_cast = match right { - #[cfg(feature = "json")] _ if right.is_json_value() => "::jsonb", _ if right.is_xml_value() => "::text", _ => "", @@ -251,14 +249,12 @@ impl<'a> Visitor<'a> for Postgres<'a> { fn visit_not_equals(&mut self, left: Expression<'a>, right: Expression<'a>) -> visitor::Result { // LHS must be cast to json/xml-text if the right is a json/xml-text value and vice versa. let right_cast = match left { - #[cfg(feature = "json")] _ if left.is_json_value() => "::jsonb", _ if left.is_xml_value() => "::text", _ => "", }; let left_cast = match right { - #[cfg(feature = "json")] _ if right.is_json_value() => "::jsonb", _ if right.is_xml_value() => "::text", _ => "", @@ -273,7 +269,7 @@ impl<'a> Visitor<'a> for Postgres<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract(&mut self, json_extract: JsonExtract<'a>) -> visitor::Result { match json_extract.path { #[cfg(feature = "mysql")] @@ -313,7 +309,7 @@ impl<'a> Visitor<'a> for Postgres<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_unquote(&mut self, json_unquote: JsonUnquote<'a>) -> visitor::Result { self.write("(")?; self.visit_expression(*json_unquote.expr)?; @@ -323,7 +319,7 @@ impl<'a> Visitor<'a> for Postgres<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_array_contains(&mut self, left: Expression<'a>, right: Expression<'a>, not: bool) -> visitor::Result { if not { self.write("( NOT ")?; @@ -340,7 +336,7 @@ impl<'a> Visitor<'a> for Postgres<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_last_array_item(&mut self, extract: JsonExtractLastArrayElem<'a>) -> visitor::Result { self.write("(")?; self.visit_expression(*extract.expr)?; @@ -350,7 +346,7 @@ impl<'a> Visitor<'a> for Postgres<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_first_array_item(&mut self, extract: JsonExtractFirstArrayElem<'a>) -> visitor::Result { self.write("(")?; self.visit_expression(*extract.expr)?; @@ -360,7 +356,7 @@ impl<'a> Visitor<'a> for Postgres<'a> { Ok(()) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_type_equals(&mut self, left: Expression<'a>, json_type: JsonType<'a>, not: bool) -> visitor::Result { self.write("JSONB_TYPEOF")?; self.write("(")?; @@ -720,7 +716,6 @@ mod tests { assert_eq!(expected_sql, sql); } - #[cfg(feature = "json")] #[test] fn equality_with_a_json_value() { let expected = expected_values( @@ -735,7 +730,6 @@ mod tests { assert_eq!(expected.1, params); } - #[cfg(feature = "json")] #[test] fn equality_with_a_lhs_json_value() { // A bit artificial, but checks if the ::jsonb casting is done correctly on the right side as well. @@ -752,7 +746,6 @@ mod tests { assert_eq!(expected.1, params); } - #[cfg(feature = "json")] #[test] fn difference_with_a_json_value() { let expected = expected_values( @@ -768,7 +761,6 @@ mod tests { assert_eq!(expected.1, params); } - #[cfg(feature = "json")] #[test] fn difference_with_a_lhs_json_value() { let expected = expected_values( @@ -898,7 +890,7 @@ mod tests { } #[test] - #[cfg(feature = "json")] + fn test_raw_json() { let (sql, params) = Postgres::build(Select::default().value(serde_json::json!({ "foo": "bar" }).raw())).unwrap(); diff --git a/quaint/src/visitor/sqlite.rs b/quaint/src/visitor/sqlite.rs index 3ac0d0866dd1..838ead467571 100644 --- a/quaint/src/visitor/sqlite.rs +++ b/quaint/src/visitor/sqlite.rs @@ -103,7 +103,7 @@ impl<'a> Visitor<'a> for Sqlite<'a> { return Err(builder.build()); } - #[cfg(feature = "json")] + Value::Json(j) => match j { Some(ref j) => { let s = serde_json::to_string(j)?; @@ -276,12 +276,12 @@ impl<'a> Visitor<'a> for Sqlite<'a> { }) } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract(&mut self, _json_extract: JsonExtract<'a>) -> visitor::Result { unimplemented!("JSON filtering is not yet supported on SQLite") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_array_contains( &mut self, _left: Expression<'a>, @@ -291,7 +291,7 @@ impl<'a> Visitor<'a> for Sqlite<'a> { unimplemented!("JSON filtering is not yet supported on SQLite") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_type_equals(&mut self, _left: Expression<'a>, _json_type: JsonType, _not: bool) -> visitor::Result { unimplemented!("JSON_TYPE is not yet supported on SQLite") } @@ -316,17 +316,17 @@ impl<'a> Visitor<'a> for Sqlite<'a> { unimplemented!("Full-text search is not yet supported on SQLite") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_last_array_item(&mut self, _extract: JsonExtractLastArrayElem<'a>) -> visitor::Result { unimplemented!("JSON filtering is not yet supported on SQLite") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_extract_first_array_item(&mut self, _extract: JsonExtractFirstArrayElem<'a>) -> visitor::Result { unimplemented!("JSON filtering is not yet supported on SQLite") } - #[cfg(all(feature = "json", any(feature = "postgresql", feature = "mysql")))] + #[cfg(any(feature = "postgresql", feature = "mysql"))] fn visit_json_unquote(&mut self, _json_unquote: JsonUnquote<'a>) -> visitor::Result { unimplemented!("JSON filtering is not yet supported on SQLite") } @@ -913,7 +913,7 @@ mod tests { } #[test] - #[cfg(feature = "json")] + fn test_raw_json() { let (sql, params) = Sqlite::build(Select::default().value(serde_json::json!({ "foo": "bar" }).raw())).unwrap(); assert_eq!("SELECT '{\"foo\":\"bar\"}'", sql);