Blame view
select_config.go
1.07 KB
8bc396eb9 reverted changes |
1 |
package webutility |
79071a5d4 Using database/sq... |
2 |
import "database/sql" |
8bc396eb9 reverted changes |
3 |
|
707782344 lint; vet |
4 |
// SelectConfig ... |
8bc396eb9 reverted changes |
5 6 7 8 |
type SelectConfig struct { ListObjType string `json:"listObjectType"` ObjType string `json:"objectType"` Type string `json:"type"` |
707782344 lint; vet |
9 |
IDField string `json:"idField"` |
8bc396eb9 reverted changes |
10 11 12 13 14 |
LabelField string `json:"labelField"` ValueField string `json:"valueField"` } // GetSelectConfig returns select configuration slice for the given object type. |
79071a5d4 Using database/sq... |
15 |
func GetSelectConfig(db *sql.DB, otype string) ([]SelectConfig, error) { |
8bc396eb9 reverted changes |
16 |
resp := make([]SelectConfig, 0) |
79071a5d4 Using database/sq... |
17 |
rows, err := db.Query(`SELECT |
8bc396eb9 reverted changes |
18 19 20 21 22 23 24 25 26 |
a.LIST_OBJECT_TYPE, a.OBJECT_TYPE, a.ID_FIELD, a.LABEL_FIELD, a.TYPE, b.FIELD FROM LIST_SELECT_CONFIG a, LIST_VALUE_FIELD b WHERE a.LIST_OBJECT_TYPE` + otype + ` AND b.LIST_TYPE = a.LIST_OBJECT_TYPE |
79071a5d4 Using database/sq... |
27 |
AND b.OBJECT_TYPE = a.OBJECT_TYPE`) |
8bc396eb9 reverted changes |
28 29 30 |
if err != nil { return nil, err } |
79071a5d4 Using database/sq... |
31 |
defer rows.Close() |
8bc396eb9 reverted changes |
32 |
|
79071a5d4 Using database/sq... |
33 34 |
var sc SelectConfig for rows.Next() { |
707782344 lint; vet |
35 |
rows.Scan(&sc.ListObjType, &sc.ObjType, &sc.IDField, &sc.LabelField, &sc.Type, &sc.ValueField) |
79071a5d4 Using database/sq... |
36 |
resp = append(resp, sc) |
8bc396eb9 reverted changes |
37 |
} |
79071a5d4 Using database/sq... |
38 39 |
if rows.Err() != nil { return nil, rows.Err() |
8bc396eb9 reverted changes |
40 41 42 43 |
} return resp, nil } |