Expand description

To do with reading values off of rusqlite::Row using FromSqlRow.

You can call Query::disperse to execute it in SQLite. That function takes a FromSqlRow that is used to get nice value from a rusqlite::Row.

This module is supposed to be stuff implementing FromSqlRow but right now it’s just zip_with_keys, which lets you get a kind of key-value mapping from a row.

Otherwise, you can get a single value using just (which this module exports) and sequences using slices or tuples & arrays up to [_;9] or do a bit of branching using Either.

// FromSqlRow is implemented on tuples & arrays.
let mut fromsql = (
    just::<Value>(),
    [just::<Value>(), just::<Value>()],
    zip_with_keys([Attribute::from_static(":db/id")]),
);

let results = Query::default()
    .push_sql(
        r#"
SELECT 0, 123
     , 0, "is your refrigerator running?"
     , 0, "better go catch itjasdkfjlsdfjalskdfjdklsf"
     , 1, x'b3ddeb4ca61f44338acd7e10117f142e'
     "#,
    )
    .disperse(fromsql, &woof)
    .unwrap();

assert_eq!(results.len(), 1); // one result returned

match results.into_iter().next().unwrap() {
    (Value::Integer(123), texts, obj) => {
        assert_eq!(
            texts,
            vec![
                Value::Text(String::from(
                    "is your refrigerator running?"
                )),
                Value::Text(String::from(
                    "better go catch itjasdkfjlsdfjalskdfjdklsf"
                )),
            ]
        );
        assert_eq!(
            obj.into_iter().collect::<Vec<_>>(),
            vec![(
                ":db/id".parse::<Attribute>().unwrap(),
                "#b3ddeb4c-a61f-4433-8acd-7e10117f142e"
                    .parse()
                    .map(Value::Entity)
                    .unwrap(),
            ),]
        );
    }
    result => assert!(false, "{:#?}", result),
}

See crate::driver for a bit more information about FromSqlRow.

Re-exports

pub use crate::driver::just;
pub use crate::driver::ColumnIndex;
pub use crate::driver::FromSqlRow;
pub use crate::sql::Query;

Structs

Serializes a map by zipping K and V. Initialize this with zip_with_keys.

Functions

Create an implementation of FromSqlRow from a function.

Given a sequence of keys (like attributes) returns an implementation of FromSqlRow that reads one Value per key and outputs an ObjectMap, a type that can serde::Serialize to a map of keys zipped with values.

Type Definitions

A typedef of the result returned by many methods.