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

Function ExampleDB_Model_selectOrInsert

example_model_test.go:206–223  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

204}
205
206func ExampleDB_Model_selectOrInsert() {
207 db := modelDB()
208
209 author := Author{
210 Name: "R. Scott Bakker",
211 }
212 created, err := db.Model(&author).
213 Column("id").
214 Where("name = ?name").
215 OnConflict("DO NOTHING"). // OnConflict is optional
216 Returning("id").
217 SelectOrInsert()
218 if err != nil {
219 panic(err)
220 }
221 fmt.Println(created, author)
222 // Output: true Author<ID=2 Name="R. Scott Bakker">
223}
224
225func ExampleDB_Model_insertDynamicTableName() {
226 type NamelessModel struct {

Callers

nothing calls this directly

Calls 7

modelDBFunction · 0.85
SelectOrInsertMethod · 0.80
ReturningMethod · 0.80
OnConflictMethod · 0.80
WhereMethod · 0.80
ColumnMethod · 0.80
ModelMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…