Skip to content

Commit 7357205

Browse files
authored
Merge pull request go-gorp#282 from brucespang/master
Don't ignore the return errors from Insert in documentation examples
2 parents bdc7c2d + e383e08 commit 7357205

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

README.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,13 @@ type InvoicePersonView struct {
436436

437437
// Create some rows
438438
p1 := &Person{0, 0, 0, "bob", "smith"}
439-
dbmap.Insert(p1)
439+
err = dbmap.Insert(p1)
440+
checkErr(err, "Insert failed")
440441

441442
// notice how we can wire up p1.Id to the invoice easily
442443
inv1 := &Invoice{0, 0, 0, "xmas order", p1.Id}
443-
dbmap.Insert(inv1)
444+
err = dbmap.Insert(inv1)
445+
checkErr(err, "Insert failed")
444446

445447
// Run your query
446448
query := "select i.Id InvoiceId, p.Id PersonId, i.Memo, p.FName " +
@@ -503,9 +505,12 @@ func InsertInv(dbmap *DbMap, inv *Invoice, per *Person) error {
503505
return err
504506
}
505507

506-
trans.Insert(per)
508+
err = trans.Insert(per)
509+
checkErr(err, "Insert failed")
510+
507511
inv.PersonId = per.Id
508-
trans.Insert(inv)
512+
err = trans.Insert(inv)
513+
checkErr(err, "Insert failed")
509514

510515
// if the commit is successful, a nil error is returned
511516
return trans.Commit()
@@ -591,12 +596,14 @@ type Person struct {
591596
}
592597

593598
p1 := &Person{0, 0, 0, "Bob", "Smith", 0}
594-
dbmap.Insert(p1) // Version is now 1
599+
err = dbmap.Insert(p1) // Version is now 1
600+
checkErr(err, "Insert failed")
595601

596602
obj, err := dbmap.Get(Person{}, p1.Id)
597603
p2 := obj.(*Person)
598604
p2.LName = "Edwards"
599-
dbmap.Update(p2) // Version is now 2
605+
_,err = dbmap.Update(p2) // Version is now 2
606+
checkErr(err, "Update failed")
600607

601608
p1.LName = "Howard"
602609

0 commit comments

Comments
 (0)