launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.5k stars 1.28k forks source link

With sqlite and chrono, NaiveTime failed to parse from `time` type #3576

Open rust-kotlin opened 4 weeks ago

rust-kotlin commented 4 weeks ago

Bug Description

When I name the type of a field in sqlite as date, and tried to use sqlx::query_as! to parse that field to a struct with chrono::NaiveDate type, I went ok with no problems. image

It went wrong when defining the type of a field as time, and tried to parse that to chrono::NaiveTime, the error is that unsupported type TIME of column #2 ("start_time"). image

Minimal Reproduction

            #[derive(Debug)]
            pub struct Time {
                pub time_id: i64,
                pub start_time: NaiveTime,
                pub end_time: NaiveTime,
                pub persons: i64,
            }

            let times: Vec<Time> = sqlx::query_as!(Time, r#"
            SELECT 
                time_id, 
                start_time, 
                end_time, 
                persons 
            FROM times
            "#)
            .fetch_all(&self.pool)
            .await?;