edgedb-rust icon indicating copy to clipboard operation
edgedb-rust copied to clipboard

implement ScalarArg for tuples

Open aljazerzen opened this issue 10 months ago • 0 comments

This should work:

#[tokio::test]
async fn tuples() -> anyhow::Result<()> {
    let client = Client::new(&SERVER.config);
    client.ensure_connected().await?;

    let res: Value = client
        .query_required_single("select <tuple<int64, int64>>(42, 3)", &())
        .await
        .unwrap();
    let Value::Tuple(res) = res else { panic!() };
    assert_eq!(res, vec![Value::Int64(42), Value::Int64(3)]);

    let res: (i64, i64) = client
        .query_required_single("select <tuple<int64, int64>>(42, 3)", &())
        .await
        .unwrap();
    assert_eq!(res, (42, 3));

    let arg = Value::Tuple(vec![Value::Int64(42), Value::Int64(3)]);
    let res: (i64, i64) = client
        .query_required_single("select <tuple<int64, int64>>$0", &(arg,))
        .await
        .unwrap();
    assert_eq!(res, (42, 3));

    let arg: (i64, i64) = (42, 3);
    let res: (i64, i64) = client
        .query_required_single("select <tuple<int64, int64>>$0", &(arg,))
        .await
        .unwrap();
    assert_eq!(res, (42, 3));

    Ok(())
}

aljazerzen avatar Jan 31 '25 11:01 aljazerzen