// Need to check for nulls here.
// Not sure how we're going to do this. We need some macro to try_get, and if it fails
// go for content::null
// https://kotiri.com/2018/01/31/postgresql-diesel-rust-types.html
Need to check for nulls here.
Not sure how we're going to do this.
Need to check for nulls here . Not sure how we ' re going to do this .
fn try_from(rows: Vec<Row>) -> Result<Self, Self::Error> {
        let mut values = Vec::new();
        for row in rows {
            let mut obj_content = Map::new();
            for i in 0..row.columns().len() {
                let column = row
                    .columns()
                    .get(i)
                    .expect("Cannot go out of range here since iterator is bound by length");
                let value = match column.type_().name() {
                    "bool" => Value::Bool(row.get(i)),
                    "oid" => {
                        unimplemented!()
                    }
                    "char" | "varchar" | "text" | "bpchar" | "name" | "unknown" => {
                        Value::String(row.get(i))
                    }
                    "int2" => Value::Number(Number::from(row.get::<_, i16>(i))),
                    "int4" => Value::Number(Number::from(row.get::<_, i32>(i))),
                    "int8" => Value::Number(Number::from(row.get::<_, i64>(i))),
                    "float4" => Value::Number(
                        Number::from_f64(row.get(i))
                            .expect("Cloud not convert to f64. Value was NaN."),
                    ),
                    "float8" => Value::Number(
                        Number::from_f64(row.get(i))
                            .expect("Cloud not convert to f64. Value was NaN."),
                    ),
                    "numeric" => {
                        let as_decimal: rust_decimal::Decimal = row.get(i);
                        Value::Number(
                            Number::from_f64(
                                as_decimal
                                    .to_f64()
                                    .expect("Could not convert decimal to f64 for reasons todo"),
                            )
                            .expect("Cloud not convert to f64. Value was NaN."),
                        )
                    }
                    "timestampz" => Value::String(row.get(i)),
                    "timestamp" => Value::String(row.get(i)),
                    "date" => Value::String(format!("{}", row.get::<_, chrono::NaiveDate>(i))),
                    _ => {
                        unimplemented!("We haven't implemented a converter for {}", column.name())
                    }
                };
                obj_content.insert(column.name().to_string(), value);
            }
            values.push(Value::Object(obj_content));
        }
        Ok(Values(values))
    }
fn try_from ( rows : Vec < Row > ) -> Result < Self , Self :: Error > { let mut values = Vec :: new ( ) ; for row in rows { let mut obj_content = Map :: new ( ) ; for i in 0 .. row . columns ( ) . len ( ) { let column = row . columns ( ) . get ( i ) . expect ( " " ) ; let value = match column . type_ ( ) . name ( ) { " " => Value :: Bool ( row . get ( i ) ) , " " => { unimplemented ! ( ) } " " | " " | " " | " " | " " | " " => { Value :: String ( row . get ( i ) ) } " " => Value :: Number ( Number :: from ( row . get :: < _ , i16 > ( i ) ) ) , " " => Value :: Number ( Number :: from ( row . get :: < _ , i32 > ( i ) ) ) , " " => Value :: Number ( Number :: from ( row . get :: < _ , i64 > ( i ) ) ) , " " => Value :: Number ( Number :: from_f64 ( row . get ( i ) ) . expect ( " " ) , ) , " " => Value :: Number ( Number :: from_f64 ( row . get ( i ) ) . expect ( " " ) , ) , " " => { let as_decimal : rust_decimal :: Decimal = row . get ( i ) ; Value :: Number ( Number :: from_f64 ( as_decimal . to_f64 ( ) . expect ( " " ) , ) . expect ( " " ) , ) } " " => Value :: String ( row . get ( i ) ) , " " => Value :: String ( row . get ( i ) ) , " " => Value :: String ( format ! ( " " row get chrono NaiveDate ( i ) ) ) , _ => { unimplemented ! ( " " column name ( ) ) } } ; obj_content . insert ( column . name ( ) . to_string ( ) , value ) ; } values . push ( Value :: Object ( obj_content ) ) ; } Ok ( Values ( values ) ) }
Need to check for nulls here.
Need to check for nulls here .
rows
Vec<Row>