Skip to content

Deserialize fromCURRENT_TIMESTAMP to chrono::DateTime<chrono::Utc>. #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xuxiaocheng0201 opened this issue Apr 4, 2024 · 0 comments

Comments

@xuxiaocheng0201
Copy link

When I deserializing from CURRENT_TIMESTAMP to chrono::DateTime<chrono::Utc>, serde_rusqlite::from_rows returns an error.

Dependencies

anyhow = "^1.0"
serde = { version = "^1.0", features = ["derive"] }
chrono = { version = "~0.4", features = ["serde"] }
rusqlite = { version = "~0.31", features = ["bundled"] }
serde_rusqlite = "~0.35"

Code

use anyhow::Result;
use chrono::{DateTime, Utc};
use rusqlite::Connection;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
struct Timed {
    time: DateTime<Utc>
}

fn main() -> Result<()> {
    let connection = Connection::open_in_memory()?;
    connection.execute("CREATE TABLE test (time TIMESTAMP)", [])?;
    connection.execute("INSERT INTO test (time) VALUES (CURRENT_TIMESTAMP)", [])?;

    let mut statement = connection.prepare("SELECT * FROM test")?;
    let mut iter = serde_rusqlite::from_rows::<Timed>(statement.query([])?);
    while let Some(timed) = iter.next() {
        let timed = timed?;
        println!("{:?}", timed);
    }
    Ok(())
}

Print

Error: Deserialization failed for column: time error: premature end of input

Thought

This may not a bug in serde_rusqlite, but it will be great if this crate can handle this situation correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant