From 59f9df9b7e999f3c7342c31d073ab8f1b670f8f1 Mon Sep 17 00:00:00 2001 From: go-jet Date: Thu, 29 Sep 2022 14:31:08 +0200 Subject: [PATCH] [postgres] Add Json literal test. --- tests/postgres/alltypes_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/postgres/alltypes_test.go b/tests/postgres/alltypes_test.go index 2a1e0e2..8a7cc41 100644 --- a/tests/postgres/alltypes_test.go +++ b/tests/postgres/alltypes_test.go @@ -1257,6 +1257,28 @@ LIMIT $6; requireLogged(t, query) } +func TestJsonLiteral(t *testing.T) { + stmt := AllTypes.UPDATE(). + SET(AllTypes.JSON.SET(Json(`{"firstName": "John", "lastName": "Doe"}`))). + WHERE(AllTypes.SmallInt.EQ(Int(14))). + RETURNING(AllTypes.JSON) + + testutils.AssertDebugStatementSql(t, stmt, ` +UPDATE test_sample.all_types +SET json = '{"firstName": "John", "lastName": "Doe"}'::json +WHERE all_types.small_int = 14 +RETURNING all_types.json AS "all_types.json"; +`) + + testutils.ExecuteInTxAndRollback(t, db, func(tx *sql.Tx) { + var res model.AllTypes + + err := stmt.Query(tx, &res) + require.NoError(t, err) + require.Equal(t, res.JSON, `{"firstName": "John", "lastName": "Doe"}`) + }) +} + var allTypesRow0 = model.AllTypes{ SmallIntPtr: testutils.Int16Ptr(14), SmallInt: 14,