MCPcopy
hub / github.com/go-gorp/gorp / DbMap

Struct DbMap

db.go:30–96  ·  view source on GitHub ↗

DbMap is the root gorp mapping object. Create one of these for each database schema you wish to map. Each DbMap contains a list of mapped tables. Example: dialect := gorp.MySQLDialect{"InnoDB", "UTF8"} dbmap := &gorp.DbMap{Db: db, Dialect: dialect}

Source from the content-addressed store, hash-verified

28// dbmap := &gorp.DbMap{Db: db, Dialect: dialect}
29//
30type DbMap struct {
31 ctx context.Context
32
33 // Db handle to use with this map
34 Db *sql.DB
35
36 // Dialect implementation to use with this map
37 Dialect Dialect
38
39 TypeConverter TypeConverter
40
41 // ExpandSlices when enabled will convert slice arguments in mappers into flat
42 // values. It will modify the query, adding more placeholders, and the mapper,
43 // adding each item of the slice as a new unique entry in the mapper. For
44 // example, given the scenario bellow:
45 //
46 // dbmap.Select(&output, "SELECT 1 FROM example WHERE id IN (:IDs)", map[string]interface{}{
47 // "IDs": []int64{1, 2, 3},
48 // })
49 //
50 // The executed query would be:
51 //
52 // SELECT 1 FROM example WHERE id IN (:IDs0,:IDs1,:IDs2)
53 //
54 // With the mapper:
55 //
56 // map[string]interface{}{
57 // "IDs": []int64{1, 2, 3},
58 // "IDs0": int64(1),
59 // "IDs1": int64(2),
60 // "IDs2": int64(3),
61 // }
62 //
63 // It is also flexible for custom slice types. The value just need to
64 // implement stringer or numberer interfaces.
65 //
66 // type CustomValue string
67 //
68 // const (
69 // CustomValueHey CustomValue = "hey"
70 // CustomValueOh CustomValue = "oh"
71 // )
72 //
73 // type CustomValues []CustomValue
74 //
75 // func (c CustomValues) ToStringSlice() []string {
76 // values := make([]string, len(c))
77 // for i := range c {
78 // values[i] = string(c[i])
79 // }
80 // return values
81 // }
82 //
83 // func query() {
84 // // ...
85 // result, err := dbmap.Select(&output, "SELECT 1 FROM example WHERE value IN (:Values)", map[string]interface{}{
86 // "Values": CustomValues([]CustomValue{CustomValueHey}),
87 // })

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected