Skip to content

sqlx FromRow to specific type #2151

Answered by sdrap
sdrap asked this question in Q&A
Discussion options

You must be logged in to vote

Discovered cargo expand so could figure out the boiler plate.

From:

...
#[derive(Debug)]
#[derive(sqlx::FromRow)]
pub struct Data{
    array_floats: Vec<f64>,
    array_int: Vec<i64>
}
...

To:

...
use ndarray::Array;

#[derive(Debug)]
pub struct Data{
    array_floats: Array1::<f64>,
    array_int: Array1::<i64>
}

// Implementation for the decode and type

impl<'a, R: ::sqlx::Row> ::sqlx::FromRow<'a, R> for Lob2
where
    &'a ::std::primitive::str: ::sqlx::ColumnIndex<R>,
    Vec<f64>: ::sqlx::decode::Decode<'a, R::Database>,
    Vec<f64>: ::sqlx::types::Type<R::Database>,
    Vec<i64>: ::sqlx::decode::Decode<'a, R::Database>,
    Vec<i64>: ::sqlx::types::Type<R::Database>,
{
    fn from…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sdrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant