Skip to content

Commit

Permalink
wrap around TRX
Browse files Browse the repository at this point in the history
  • Loading branch information
safaci2000 committed Oct 7, 2024
1 parent 31a6b95 commit 2a3fafd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/postgres/alltypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,43 @@ func TestTimeExpression(t *testing.T) {
require.NoError(t, err)
}

func TestIntervalUpsert(t *testing.T) {
testutils.ExecuteInTxAndRollback(t, db, func(tx *sql.Tx) {
stmt := SELECT(Employee.AllColumns).FROM(Employee).
WHERE(Employee.EmployeeID.EQ(Int(1)))

//Validate initial dataset
var windy model.Employee
err := stmt.Query(db, &windy)
assert.Equal(t, windy.EmployeeID, int32(1))
assert.Equal(t, windy.FirstName, "Windy")
assert.Equal(t, windy.LastName, "Hays")
assert.Equal(t, *windy.PtoAccrual, "22:00:00")
assert.Nil(t, err)
windy.PtoAccrual = ptr.Of("3h")
//Update data
updateStmt := Employee.UPDATE(Employee.PtoAccrual).SET(
Employee.PtoAccrual.SET(INTERVAL(3, HOUR)),
).WHERE(Employee.EmployeeID.EQ(Int(1))).RETURNING(Employee.AllColumns)

err = updateStmt.Query(db, &windy)
err = stmt.Query(db, &windy)
assert.Nil(t, err)
assert.Equal(t, *windy.PtoAccrual, "03:00:00")
//Upsert dataset with a different value
windy.PtoAccrual = ptr.Of("5h")
insertStmt := Employee.INSERT(Employee.AllColumns).
MODEL(&windy).
ON_CONFLICT(Employee.EmployeeID).
DO_UPDATE(SET(
Employee.PtoAccrual.SET(Employee.EXCLUDED.PtoAccrual),
)).RETURNING(Employee.AllColumns)
err = insertStmt.Query(db, &windy)
assert.Nil(t, err)
assert.Equal(t, *windy.PtoAccrual, "05:00:00")
})
}

func TestInterval(t *testing.T) {
skipForCockroachDB(t)

Expand Down

0 comments on commit 2a3fafd

Please sign in to comment.