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

Function ExampleDB_Model_bulkInsertSlice

example_model_test.go:121–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

119}
120
121func ExampleDB_Model_bulkInsertSlice() {
122 db := modelDB()
123
124 books := []Book{{
125 Title: "new book 1",
126 }, {
127 Title: "new book 2",
128 }}
129 _, err := db.Model(&books).Insert()
130 if err != nil {
131 panic(err)
132 }
133 fmt.Println(books)
134 // Output: [Book<Id=4 Title="new book 1"> Book<Id=5 Title="new book 2">]
135
136 for i := range books {
137 _, err := db.Model(&books[i]).WherePK().Delete()
138 if err != nil {
139 panic(err)
140 }
141 }
142}
143
144func ExampleDB_Model_insertOnConflictDoNothing() {
145 db := modelDB()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…