Skip to content

Commit

Permalink
Merge pull request #4306 from meeshal/add_row_to_json_support
Browse files Browse the repository at this point in the history
add Record support for 1 element tuples
  • Loading branch information
weiznich authored Oct 25, 2024
2 parents 73a9d3e + d0398e7 commit 41f6553
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion diesel/src/pg/types/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ where
T: QueryFragment<Pg>,
{
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
out.push_sql("(");
out.push_sql("ROW(");
self.0.walk_ast(out.reborrow())?;
out.push_sql(")");
Ok(())
Expand Down Expand Up @@ -198,6 +198,9 @@ mod tests {
>("SELECT ((4, NULL), NULL)")
.get_result::<((Option<i32>, Option<String>), Option<i32>)>(conn);
assert_eq!(Ok(((Some(4), None), None)), tup);

let tup = sql::<Record<(Integer,)>>("SELECT ROW(1)").get_result::<(i32,)>(conn);
assert_eq!(Ok((1,)), tup);
}

#[test]
Expand All @@ -212,6 +215,10 @@ mod tests {
let res = crate::select(tup.eq(((2, "bye"), 3))).get_result(conn);
assert_eq!(Ok(true), res);

let tup = sql::<Record<(Integer,)>>("ROW(3)");
let res = crate::select(tup.eq((3,))).get_result(conn);
assert_eq!(Ok(true), res);

let tup = sql::<
Record<(
Record<(Nullable<Integer>, Nullable<Text>)>,
Expand Down

0 comments on commit 41f6553

Please sign in to comment.