MCPcopy Create free account
hub / github.com/go-pg/pg / ExampleDB_Model_insertOnConflictDoNothing

Function ExampleDB_Model_insertOnConflictDoNothing

example_model_test.go:144–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142}
143
144func ExampleDB_Model_insertOnConflictDoNothing() {
145 db := modelDB()
146
147 book := &Book{
148 ID: 100,
149 Title: "book 100",
150 }
151
152 for i := 0; i < 2; i++ {
153 res, err := db.Model(book).OnConflict("DO NOTHING").Insert()
154 if err != nil {
155 panic(err)
156 }
157 if res.RowsAffected() > 0 {
158 fmt.Println("created")
159 } else {
160 fmt.Println("did nothing")
161 }
162 }
163
164 _, err := db.Model(book).WherePK().Delete()
165 if err != nil {
166 panic(err)
167 }
168
169 // Output: created
170 // did nothing
171}
172
173func ExampleDB_Model_insertOnConflictDoUpdate() {
174 db := modelDB()

Callers

nothing calls this directly

Calls 7

modelDBFunction · 0.85
InsertMethod · 0.80
OnConflictMethod · 0.80
DeleteMethod · 0.80
WherePKMethod · 0.80
ModelMethod · 0.65
RowsAffectedMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…