Skip to content

Commit

Permalink
[postgres] Add Json literal test.
Browse files Browse the repository at this point in the history
  • Loading branch information
go-jet committed Sep 29, 2022
1 parent f772f90 commit 59f9df9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/postgres/alltypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 59f9df9

Please sign in to comment.