I have a struct as follows?
pub struct Instrument {
pub id:i32,
pub expiry_on: <this should be a date field>
}
What should I give the type of expiry_on. I want to use the struct inside sqlx::query_as!() to fetch records from postgres ?
expiry_on is a timestampz Postgres field.
Under the assumption that your expiry_on field in postgres is a timestamptz: Depending on the time library you use, you will either want to add the chrono feature or the time feature to sqlx. Which you can do in Cargo.toml like this:
[dependencies]
sqlx = { version = "*", features = [ "chrono" ] }
or
sqlx = { version = "*", features = [ "time" ] }
instead of
sqlx = "*"
Where * is whatever version you're using.
You then change the following in Instrument (assuming chrono):
pub struct Instrument {
pub id: i32,
pub expiry_on: chrono::DateTime<chrono::Utc>,
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With