Skip to content

Commit

Permalink
feat(quaint): remove chrono conditional flag (#4227)
Browse files Browse the repository at this point in the history
* feat(quaint): remove "chrono" conditional flag

* feat(quaint): remove "chrono" conditional flag from tests as well
  • Loading branch information
jkomyno authored Sep 13, 2023
1 parent 9e8c303 commit 5106138
Show file tree
Hide file tree
Showing 20 changed files with 11 additions and 168 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=chrono --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=sqlite --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql"
- "--lib --no-default-features --features=postgresql --features=chrono --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql"
- "--lib --no-default-features --features=mysql --features=chrono --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql"
- "--lib --no-default-features --features=mssql --features=chrono --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql --features=json --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 @@ -56,7 +56,6 @@ napi-derive = "2.12.4"
path = "quaint"
features = [
"bigdecimal",
"chrono",
"expose-drivers",
"fmt-sql",
"json",
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=chrono --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=sqlite --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql"
- "--lib --no-default-features --features=postgresql --features=chrono --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=postgresql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql"
- "--lib --no-default-features --features=mysql --features=chrono --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mysql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql"
- "--lib --no-default-features --features=mssql --features=chrono --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--lib --no-default-features --features=mssql --features=json --features=uuid --features=pooled --features=serde-support --features=bigdecimal"
- "--doc --features=all"
env:
TEST_MYSQL: "mysql://root:prisma@localhost:3306/prisma"
Expand Down
7 changes: 3 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 = [
"chrono",
"json",
"mssql",
"mysql",
Expand Down Expand Up @@ -60,10 +59,10 @@ postgresql = [
]

json = ["serde_json", "base64"]
mssql = ["tiberius", "uuid", "chrono", "tokio-util", "tokio/time", "tokio/net", "either"]
mssql = ["tiberius", "uuid", "tokio-util", "tokio/time", "tokio/net", "either"]
mysql = ["mysql_async", "tokio/time", "lru-cache"]
pooled = ["mobc"]
serde-support = ["serde", "chrono/serde"]
serde-support = ["serde"]
sqlite = ["rusqlite", "tokio/sync"]
bigdecimal = ["bigdecimal_"]
fmt-sql = ["sqlformat"]
Expand All @@ -83,7 +82,7 @@ hex = "0.4"

either = { version = "1.6", optional = true }
base64 = { version = "0.12.3", optional = true }
chrono = { version = "0.4", optional = true, default-features = false }
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"] }
native-tls = { version = "0.2", optional = true }
Expand Down
44 changes: 0 additions & 44 deletions quaint/src/ast/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::error::{Error, ErrorKind};

#[cfg(feature = "bigdecimal")]
use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive};
#[cfg(feature = "chrono")]
use chrono::{DateTime, NaiveDate, NaiveTime, Utc};
#[cfg(feature = "json")]
use serde_json::{Number, Value as JsonValue};
Expand Down Expand Up @@ -75,16 +74,10 @@ pub enum Value<'a> {
#[cfg_attr(feature = "docs", doc(cfg(feature = "uuid")))]
/// An UUID value.
Uuid(Option<Uuid>),
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
/// A datetime value.
DateTime(Option<DateTime<Utc>>),
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
/// A date value.
Date(Option<NaiveDate>),
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
/// A time value.
Time(Option<NaiveTime>),
}
Expand Down Expand Up @@ -139,11 +132,8 @@ impl<'a> fmt::Display for Value<'a> {
Value::Json(val) => val.as_ref().map(|v| write!(f, "{v}")),
#[cfg(feature = "uuid")]
Value::Uuid(val) => val.map(|v| write!(f, "\"{v}\"")),
#[cfg(feature = "chrono")]
Value::DateTime(val) => val.map(|v| write!(f, "\"{v}\"")),
#[cfg(feature = "chrono")]
Value::Date(val) => val.map(|v| write!(f, "\"{v}\"")),
#[cfg(feature = "chrono")]
Value::Time(val) => val.map(|v| write!(f, "\"{v}\"")),
};

Expand Down Expand Up @@ -190,11 +180,8 @@ impl<'a> From<Value<'a>> for serde_json::Value {
Value::Json(v) => v,
#[cfg(feature = "uuid")]
Value::Uuid(u) => u.map(|u| serde_json::Value::String(u.hyphenated().to_string())),
#[cfg(feature = "chrono")]
Value::DateTime(dt) => dt.map(|dt| serde_json::Value::String(dt.to_rfc3339())),
#[cfg(feature = "chrono")]
Value::Date(date) => date.map(|date| serde_json::Value::String(format!("{date}"))),
#[cfg(feature = "chrono")]
Value::Time(time) => time.map(|time| serde_json::Value::String(format!("{time}"))),
};

Expand Down Expand Up @@ -304,22 +291,16 @@ impl<'a> Value<'a> {
}

/// Creates a new datetime value.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn datetime(value: DateTime<Utc>) -> Self {
Value::DateTime(Some(value))
}

/// Creates a new date value.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn date(value: NaiveDate) -> Self {
Value::Date(Some(value))
}

/// Creates a new time value.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn time(value: NaiveTime) -> Self {
Value::Time(Some(value))
}
Expand Down Expand Up @@ -357,11 +338,8 @@ impl<'a> Value<'a> {
Value::Numeric(r) => r.is_none(),
#[cfg(feature = "uuid")]
Value::Uuid(u) => u.is_none(),
#[cfg(feature = "chrono")]
Value::DateTime(dt) => dt.is_none(),
#[cfg(feature = "chrono")]
Value::Date(d) => d.is_none(),
#[cfg(feature = "chrono")]
Value::Time(t) => t.is_none(),
#[cfg(feature = "json")]
Value::Json(json) => json.is_none(),
Expand Down Expand Up @@ -564,15 +542,11 @@ impl<'a> Value<'a> {
}

/// `true` if the `Value` is a DateTime.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn is_datetime(&self) -> bool {
matches!(self, Value::DateTime(_))
}

/// Returns a `DateTime` if the value is a `DateTime`, otherwise `None`.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn as_datetime(&self) -> Option<DateTime<Utc>> {
match self {
Value::DateTime(dt) => *dt,
Expand All @@ -581,15 +555,11 @@ impl<'a> Value<'a> {
}

/// `true` if the `Value` is a Date.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn is_date(&self) -> bool {
matches!(self, Value::Date(_))
}

/// Returns a `NaiveDate` if the value is a `Date`, otherwise `None`.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn as_date(&self) -> Option<NaiveDate> {
match self {
Value::Date(dt) => *dt,
Expand All @@ -598,15 +568,11 @@ impl<'a> Value<'a> {
}

/// `true` if the `Value` is a `Time`.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn is_time(&self) -> bool {
matches!(self, Value::Time(_))
}

/// Returns a `NaiveTime` if the value is a `Time`, otherwise `None`.
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
pub const fn as_time(&self) -> Option<NaiveTime> {
match self {
Value::Time(time) => *time,
Expand Down Expand Up @@ -687,11 +653,8 @@ value!(val: &'a [u8], Bytes, val.into());
value!(val: f64, Double, val);
value!(val: f32, Float, val);

#[cfg(feature = "chrono")]
value!(val: DateTime<Utc>, DateTime, val);
#[cfg(feature = "chrono")]
value!(val: chrono::NaiveTime, Time, val);
#[cfg(feature = "chrono")]
value!(val: chrono::NaiveDate, Date, val);
#[cfg(feature = "bigdecimal")]
value!(val: BigDecimal, Numeric, val);
Expand Down Expand Up @@ -761,8 +724,6 @@ impl<'a> TryFrom<Value<'a>> for bool {
}
}

#[cfg(feature = "chrono")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "chrono")))]
impl<'a> TryFrom<Value<'a>> for DateTime<Utc> {
type Error = Error;

Expand Down Expand Up @@ -926,7 +887,6 @@ impl<'a> IntoIterator for Values<'a> {
#[cfg(test)]
mod tests {
use super::*;
#[cfg(feature = "chrono")]
use std::str::FromStr;

#[test]
Expand Down Expand Up @@ -965,7 +925,6 @@ mod tests {
}

#[test]
#[cfg(feature = "chrono")]
fn a_parameterized_value_of_datetimes_can_be_converted_into_a_vec() {
let datetime = DateTime::from_str("2019-07-27T05:30:30Z").expect("parsing date/time");
let pv = Value::array(vec![datetime]);
Expand All @@ -981,7 +940,6 @@ mod tests {
}

#[test]
#[cfg(feature = "chrono")]
fn display_format_for_datetime() {
let dt: DateTime<Utc> = DateTime::from_str("2019-07-27T05:30:30Z").expect("failed while parsing date");
let pv = Value::datetime(dt);
Expand All @@ -990,7 +948,6 @@ mod tests {
}

#[test]
#[cfg(feature = "chrono")]
fn display_format_for_date() {
let date = NaiveDate::from_ymd_opt(2022, 8, 11).unwrap();
let pv = Value::date(date);
Expand All @@ -999,7 +956,6 @@ mod tests {
}

#[test]
#[cfg(feature = "chrono")]
fn display_format_for_time() {
let time = NaiveTime::from_hms_opt(16, 17, 00).unwrap();
let pv = Value::time(time);
Expand Down
9 changes: 0 additions & 9 deletions quaint/src/connector/mssql/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ impl<'a> IntoSql<'a> for &'a Value<'a> {
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(),
#[cfg(feature = "chrono")]
Value::DateTime(val) => val.into_sql(),
#[cfg(feature = "chrono")]
Value::Date(val) => val.into_sql(),
#[cfg(feature = "chrono")]
Value::Time(val) => val.into_sql(),
}
}
Expand Down Expand Up @@ -60,40 +57,34 @@ impl TryFrom<ColumnData<'static>> for Value<'static> {
let kind = ErrorKind::conversion("Please enable `bigdecimal` feature to read numeric values");
return Err(Error::builder(kind).build());
}
#[cfg(feature = "chrono")]
dt @ ColumnData::DateTime(_) => {
use tiberius::time::chrono::{DateTime, NaiveDateTime, Utc};

let dt = NaiveDateTime::from_sql(&dt)?.map(|dt| DateTime::<Utc>::from_utc(dt, Utc));
Value::DateTime(dt)
}
#[cfg(feature = "chrono")]
dt @ ColumnData::SmallDateTime(_) => {
use tiberius::time::chrono::{DateTime, NaiveDateTime, Utc};

let dt = NaiveDateTime::from_sql(&dt)?.map(|dt| DateTime::<Utc>::from_utc(dt, Utc));
Value::DateTime(dt)
}
#[cfg(feature = "chrono")]
dt @ ColumnData::Time(_) => {
use tiberius::time::chrono::NaiveTime;

Value::Time(NaiveTime::from_sql(&dt)?)
}
#[cfg(feature = "chrono")]
dt @ ColumnData::Date(_) => {
use tiberius::time::chrono::NaiveDate;
Value::Date(NaiveDate::from_sql(&dt)?)
}
#[cfg(feature = "chrono")]
dt @ ColumnData::DateTime2(_) => {
use tiberius::time::chrono::{DateTime, NaiveDateTime, Utc};

let dt = NaiveDateTime::from_sql(&dt)?.map(|dt| DateTime::<Utc>::from_utc(dt, Utc));

Value::DateTime(dt)
}
#[cfg(feature = "chrono")]
dt @ ColumnData::DateTimeOffset(_) => {
use tiberius::time::chrono::{DateTime, Utc};

Expand Down
19 changes: 0 additions & 19 deletions quaint/src/connector/mysql/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
connector::{queryable::TakeRow, TypeIdentifier},
error::{Error, ErrorKind},
};
#[cfg(feature = "chrono")]
use chrono::{DateTime, Datelike, NaiveDate, NaiveDateTime, NaiveTime, Timelike, Utc};
use mysql_async::{
self as my,
Expand Down Expand Up @@ -54,15 +53,12 @@ pub fn conv_params(params: &[Value<'_>]) -> crate::Result<my::Params> {
},
#[cfg(feature = "uuid")]
Value::Uuid(u) => u.map(|u| my::Value::Bytes(u.hyphenated().to_string().into_bytes())),
#[cfg(feature = "chrono")]
Value::Date(d) => {
d.map(|d| my::Value::Date(d.year() as u16, d.month() as u8, d.day() as u8, 0, 0, 0, 0))
}
#[cfg(feature = "chrono")]
Value::Time(t) => {
t.map(|t| my::Value::Time(false, 0, t.hour() as u8, t.minute() as u8, t.second() as u8, 0))
}
#[cfg(feature = "chrono")]
Value::DateTime(dt) => dt.map(|dt| {
my::Value::Date(
dt.year() as u16,
Expand Down Expand Up @@ -276,7 +272,6 @@ impl TakeRow for my::Row {
})?),
my::Value::Float(f) => Value::from(f),
my::Value::Double(f) => Value::from(f),
#[cfg(feature = "chrono")]
my::Value::Date(year, month, day, hour, min, sec, micro) => {
if day == 0 || month == 0 {
let msg = format!(
Expand All @@ -294,7 +289,6 @@ impl TakeRow for my::Row {

Value::datetime(DateTime::<Utc>::from_utc(dt, Utc))
}
#[cfg(feature = "chrono")]
my::Value::Time(is_neg, days, hours, minutes, seconds, micros) => {
if is_neg {
let kind = ErrorKind::conversion("Failed to convert a negative time");
Expand Down Expand Up @@ -322,11 +316,8 @@ impl TakeRow for my::Row {
t if t.is_bytes() => Value::Bytes(None),
#[cfg(feature = "bigdecimal")]
t if t.is_real() => Value::Numeric(None),
#[cfg(feature = "chrono")]
t if t.is_datetime() => Value::DateTime(None),
#[cfg(feature = "chrono")]
t if t.is_time() => Value::Time(None),
#[cfg(feature = "chrono")]
t if t.is_date() => Value::Date(None),
#[cfg(feature = "json")]
t if t.is_json() => Value::Json(None),
Expand All @@ -337,16 +328,6 @@ impl TakeRow for my::Row {
return Err(Error::builder(kind).build());
}
},
#[cfg(not(feature = "chrono"))]
typ => {
let msg = format!(
"Value of type {:?} is not supported with the current configuration",
typ
);

let kind = ErrorKind::conversion(msg);
Err(Error::builder(kind).build())?
}
};

Ok(res)
Expand Down
Loading

0 comments on commit 5106138

Please sign in to comment.