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

Function ExampleDB_Model_discardUnknownColumns

example_model_test.go:1089–1107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1087}
1088
1089func ExampleDB_Model_discardUnknownColumns() {
1090 type Model1 struct {
1091 }
1092
1093 var model1 Model1
1094 _, err := pgdb.QueryOne(&model1, "SELECT 1 AS id")
1095 fmt.Printf("Model1: %v\n", err)
1096
1097 type Model2 struct {
1098 tableName struct{} `pg:",discard_unknown_columns"`
1099 }
1100
1101 var model2 Model2
1102 _, err = pgdb.QueryOne(&model2, "SELECT 1 AS id")
1103 fmt.Printf("Model2: %v\n", err)
1104
1105 // Output: Model1: pg: can't find column=id in model=Model1 (prefix the column with underscore or use discard_unknown_columns)
1106 // Model2: <nil>
1107}
1108
1109func ExampleDB_Model_softDelete() {
1110 type Flight struct {

Callers

nothing calls this directly

Calls 2

QueryOneMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…