pub fn encode_datums_as_json<'a, I>(
    datums: I,
    names_types: &[(ColumnName, ColumnType)],
    include_transaction: bool,
) -> serde_json::value::Value
where
    I: IntoIterator<Item = Datum<'a>>,
{
    let mut name_idx = 0;
    let namer = &mut move || {
        let ret = format!("record{}", name_idx);
        name_idx += 1;
        ret
    };
    // todo@jldlaughlin: this is awful and hacky! revisit
    let value_fields = datums
        .into_iter()
        .enumerate()
        .map(|(i, datum)| {
            if i >= names_types.len() && include_transaction {
                let transaction_id = TypedDatum::new(
                    datum.unwrap_list().into_first(),
                    ColumnType {
                        scalar_type: ScalarType::String,
                        nullable: false,
                    },
                )
                .json(namer);
                ("transaction".to_owned(), json!({ "id": transaction_id }))
            } else {
                (
                    names_types[i].0.as_str().to_owned(),
                    TypedDatum::new(datum, names_types[i].1.clone()).json(namer),
                )
            }
        })
        .collect();
    serde_json::value::Value::Object(value_fields)
}
/// Encodes a sequence of `Datum` as JSON, using supplied column names and types.
Encodes a sequence of `Datum` as JSON, using supplied column names and types.
Encodes a sequence of ` Datum ` as JSON using supplied column names and types .
pub fn encode_datums_as_json<'a, I>(
    datums: I,
    names_types: &[(ColumnName, ColumnType)],
    include_transaction: bool,
) -> serde_json::value::Value
where
    I: IntoIterator<Item = Datum<'a>>,
{
    let mut name_idx = 0;
    let namer = &mut move || {
        let ret = format!("record{}", name_idx);
        name_idx += 1;
        ret
    };
    // todo@jldlaughlin: this is awful and hacky! revisit
    let value_fields = datums
        .into_iter()
        .enumerate()
        .map(|(i, datum)| {
            if i >= names_types.len() && include_transaction {
                let transaction_id = TypedDatum::new(
                    datum.unwrap_list().into_first(),
                    ColumnType {
                        scalar_type: ScalarType::String,
                        nullable: false,
                    },
                )
                .json(namer);
                ("transaction".to_owned(), json!({ "id": transaction_id }))
            } else {
                (
                    names_types[i].0.as_str().to_owned(),
                    TypedDatum::new(datum, names_types[i].1.clone()).json(namer),
                )
            }
        })
        .collect();
    serde_json::value::Value::Object(value_fields)
}
pub fn encode_datums_as_json < ' a , I > ( datums : I , names_types : & [ ( ColumnName , ColumnType ) ] , include_transaction : bool , ) -> serde_json :: value :: Value where I : IntoIterator < Item = Datum < ' a > > , { let mut name_idx = 0 ; let namer = & mut move | | { let ret = format ! ( " " name_idx ) ; name_idx += 1 ; ret } ; // todo@jldlaughlin: this is awful and hacky! revisit let value_fields = datums . into_iter ( ) . enumerate ( ) . map ( | ( i , datum ) | { if i >= names_types . len ( ) && include_transaction { let transaction_id = TypedDatum :: new ( datum . unwrap_list ( ) . into_first ( ) , ColumnType { scalar_type : ScalarType :: String , nullable : false , } , ) . json ( namer ) ; ( " " . to_owned ( ) , json ! ( { " " transaction_id } ) ) } else { ( names_types [ i ] . 0 . as_str ( ) . to_owned ( ) , TypedDatum :: new ( datum , names_types [ i ] . 1 . clone ( ) ) . json ( namer ) , ) } } ) . collect ( ) ; serde_json :: value :: Value :: Object ( value_fields ) }
Encodes a sequence of `Datum` as JSON, using supplied column names and types.
Encodes a sequence of ` Datum ` as JSON using supplied column names and types .
datums
I
names_types
&[(ColumnName, ColumnType)]
include_transaction
bool
datums
I
names_types
&[(ColumnName, ColumnType)]
include_transaction
bool