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