From 44e0ff10656a4a29643768ee2342c7b74be451e7 Mon Sep 17 00:00:00 2001 From: Sam Ansmink Date: Tue, 27 Aug 2024 19:17:11 +0200 Subject: [PATCH] Fix CI (#375) * add time option to satisfy clippy * attempt to satisfy clippy --- crates/duckdb/Cargo.toml | 3 ++ crates/duckdb/src/column.rs | 2 +- crates/duckdb/src/types/mod.rs | 73 ---------------------------------- 3 files changed, 4 insertions(+), 74 deletions(-) diff --git a/crates/duckdb/Cargo.toml b/crates/duckdb/Cargo.toml index d2783176..e04260e4 100644 --- a/crates/duckdb/Cargo.toml +++ b/crates/duckdb/Cargo.toml @@ -32,6 +32,9 @@ extensions-full = ["json", "parquet", "vtab-full"] buildtime_bindgen = ["libduckdb-sys/buildtime_bindgen"] modern-full = ["chrono", "serde_json", "url", "r2d2", "uuid", "polars"] polars = ["dep:polars"] +# FIXME: These were added to make clippy happy: these features appear unused and should perhaps be removed +column_decltype = [] +extra_check = [] [dependencies] libduckdb-sys = { workspace = true } diff --git a/crates/duckdb/src/column.rs b/crates/duckdb/src/column.rs index 8e898fef..8d4c8935 100644 --- a/crates/duckdb/src/column.rs +++ b/crates/duckdb/src/column.rs @@ -146,7 +146,7 @@ impl Statement<'_> { #[cfg(feature = "column_decltype")] pub fn columns(&self) -> Vec { let n = self.column_count(); - let mut cols = Vec::with_capacity(n as usize); + let mut cols = Vec::with_capacity(n); for i in 0..n { let name = self.column_name_unwrap(i); let slice = self.stmt.column_decltype(i); diff --git a/crates/duckdb/src/types/mod.rs b/crates/duckdb/src/types/mod.rs index 6b65a9c1..f8ae5c58 100644 --- a/crates/duckdb/src/types/mod.rs +++ b/crates/duckdb/src/types/mod.rs @@ -1,68 +1,3 @@ -//! Traits dealing with DuckDB data types. -//! -//! DuckDB uses a [dynamic type system](https://www.sqlite.org/datatype3.html). Implementations of -//! the [`ToSql`] and [`FromSql`] traits are provided for the basic types that -//! DuckDB provides methods for: -//! -//! * Strings (`String` and `&str`) -//! * Blobs (`Vec` and `&[u8]`) -//! * Numbers -//! -//! The number situation is a little complicated due to the fact that all -//! numbers in DuckDB are stored as `INTEGER` (`i64`) or `REAL` (`f64`). -//! -//! [`ToSql`] and [`FromSql`] are implemented for all primitive number types. -//! [`FromSql`] has different behaviour depending on the SQL and Rust types, and -//! the value. -//! -//! * `INTEGER` to integer: returns an -//! [`Error::IntegralValueOutOfRange`](crate::Error::IntegralValueOutOfRange) -//! error if the value does not fit in the Rust type. -//! * `REAL` to integer: always returns an -//! [`Error::InvalidColumnType`](crate::Error::InvalidColumnType) error. -//! * `INTEGER` to float: casts using `as` operator. Never fails. -//! * `REAL` to float: casts using `as` operator. Never fails. -//! -//! [`ToSql`] always succeeds except when storing a `u64` or `usize` value that -//! cannot fit in an `INTEGER` (`i64`). Also note that DuckDB ignores column -//! types, so if you store an `i64` in a column with type `REAL` it will be -//! stored as an `INTEGER`, not a `REAL`. -//! -//! If the `time` feature is enabled, implementations are -//! provided for `time::OffsetDateTime` that use the RFC 3339 date/time format, -//! `"%Y-%m-%dT%H:%M:%S.%fZ"`, to store time values as strings. These values -//! can be parsed by SQLite's builtin -//! [datetime](https://www.sqlite.org/lang_datefunc.html) functions. If you -//! want different storage for datetimes, you can use a newtype. -#![cfg_attr( - feature = "time", - doc = r##" -For example, to store datetimes as `i64`s counting the number of seconds since -the Unix epoch: - -``` -use duckdb::types::{FromSql, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; -use duckdb::Result; - -pub struct DateTimeSql(pub time::OffsetDateTime); - -impl FromSql for DateTimeSql { - fn column_result(value: ValueRef) -> FromSqlResult { - i64::column_result(value).map(|as_i64| { - DateTimeSql(time::OffsetDateTime::from_unix_timestamp(as_i64)) - }) - } -} - -impl ToSql for DateTimeSql { - fn to_sql(&self) -> Result { - Ok(self.0.timestamp().into()) - } -} -``` - -"## -)] //! [`ToSql`] and [`FromSql`] are also implemented for `Option` where `T` //! implements [`ToSql`] or [`FromSql`] for the cases where you want to know if //! a value was NULL (which gets translated to `None`). @@ -395,10 +330,6 @@ mod test { assert!(is_invalid_column_type(row.get::<_, i64>(0).err().unwrap())); assert!(is_invalid_column_type(row.get::<_, c_double>(0).err().unwrap())); assert!(is_invalid_column_type(row.get::<_, String>(0).err().unwrap())); - #[cfg(feature = "time")] - assert!(is_invalid_column_type( - row.get::<_, time::OffsetDateTime>(0).err().unwrap() - )); assert!(is_invalid_column_type(row.get::<_, Option>(0).err().unwrap())); // 1 is actually a text (String) @@ -426,10 +357,6 @@ mod test { assert!(is_invalid_column_type(row.get::<_, c_double>(4).err().unwrap())); assert!(is_invalid_column_type(row.get::<_, String>(4).err().unwrap())); assert!(is_invalid_column_type(row.get::<_, Vec>(4).err().unwrap())); - #[cfg(feature = "time")] - assert!(is_invalid_column_type( - row.get::<_, time::OffsetDateTime>(4).err().unwrap() - )); Ok(()) }