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

Function ExampleDB_Model_createTable

example_test.go:230–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

228}
229
230func ExampleDB_Model_createTable() {
231 type Model1 struct {
232 Id int
233 }
234
235 type Model2 struct {
236 Id int
237 Name string
238
239 Model1Id int `pg:"on_delete:RESTRICT,on_update: CASCADE"`
240 Model1 *Model1 `pg:"rel:has-one"`
241 }
242
243 for _, model := range []interface{}{&Model1{}, &Model2{}} {
244 err := pgdb.Model(model).CreateTable(&orm.CreateTableOptions{
245 Temp: true, // create temp table
246 FKConstraints: true,
247 })
248 panicIf(err)
249 }
250
251 var info []struct {
252 ColumnName string
253 DataType string
254 }
255 _, err := pgdb.Query(&info, `
256 SELECT column_name, data_type
257 FROM information_schema.columns
258 WHERE table_name = 'model2'
259 `)
260 panicIf(err)
261 fmt.Println(info)
262 // Output: [{id bigint} {name text} {model1_id bigint}]
263}
264
265func ExampleInts() {
266 var nums pg.Ints

Callers

nothing calls this directly

Calls 4

CreateTableMethod · 0.80
panicIfFunction · 0.70
ModelMethod · 0.65
QueryMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…