MCPcopy
hub / github.com/go-gorp/gorp / TestTransactionExecNamedPostgres

Function TestTransactionExecNamedPostgres

gorp_test.go:1490–1537  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1488}
1489
1490func TestTransactionExecNamedPostgres(t *testing.T) {
1491 if os.Getenv("GORP_TEST_DIALECT") != "postgres" {
1492 return
1493 }
1494 dbmap := initDBMap(t)
1495 defer dropAndClose(dbmap)
1496 trans, err := dbmap.Begin()
1497 if err != nil {
1498 panic(err)
1499 }
1500 // exec should support named params
1501 args := map[string]interface{}{
1502 "created": 100,
1503 "updated": 200,
1504 "memo": "zzTest",
1505 "personID": 0,
1506 "isPaid": false,
1507 }
1508 _, err = trans.Exec(`INSERT INTO invoice_test ("Created", "Updated", "Memo", "PersonId", "IsPaid") Values(:created, :updated, :memo, :personID, :isPaid)`, args)
1509 if err != nil {
1510 panic(err)
1511 }
1512 var checkMemo = func(want string) {
1513 args := map[string]interface{}{
1514 "memo": want,
1515 }
1516 memo, err := trans.SelectStr(`select "Memo" from invoice_test where "Memo" = :memo`, args)
1517 if err != nil {
1518 panic(err)
1519 }
1520 if memo != want {
1521 t.Errorf("%q != %q", want, memo)
1522 }
1523 }
1524 checkMemo("zzTest")
1525
1526 // exec should still work with ? params
1527 _, err = trans.Exec(`INSERT INTO invoice_test ("Created", "Updated", "Memo", "PersonId", "IsPaid") Values($1, $2, $3, $4, $5)`, 10, 15, "yyTest", 0, true)
1528
1529 if err != nil {
1530 panic(err)
1531 }
1532 checkMemo("yyTest")
1533 err = trans.Commit()
1534 if err != nil {
1535 panic(err)
1536 }
1537}
1538
1539func TestSavepoint(t *testing.T) {
1540 dbmap := initDBMap(t)

Callers

nothing calls this directly

Calls 6

initDBMapFunction · 0.85
dropAndCloseFunction · 0.85
BeginMethod · 0.80
CommitMethod · 0.80
ExecMethod · 0.65
SelectStrMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…