()
| 228 | } |
| 229 | |
| 230 | func 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 | |
| 265 | func ExampleInts() { |
| 266 | var nums pg.Ints |
nothing calls this directly
no test coverage detected
searching dependent graphs…