Skip to content

Instantly share code, notes, and snippets.

@AbsolutelySaurabh
Last active April 18, 2019 05:59
Show Gist options
  • Save AbsolutelySaurabh/939c66b1aa8111d52a366f7071f9dbc5 to your computer and use it in GitHub Desktop.
Save AbsolutelySaurabh/939c66b1aa8111d52a366f7071f9dbc5 to your computer and use it in GitHub Desktop.
//db.go
SELECT_DISTINCT_MASTER_TYPES = "select distinct master_type from master_types"
//admin.go
master_type := Admin.AddResource(&models.MasterType{}, &admin.Config{
Permission: configuration.GetPermission(C.MODEL_MASTER_TYPE),
PageCount: C.PAGE_COUNT})
master_type.Meta(&admin.Meta{
Name: "Master_Type",
Type: "select_one",
Collection: getMasterTypeCollection,
})
func getMasterTypeCollection(res interface{}, ctx *qor.Context) (results [][]string) {
db := configuration.GetDB(C.READ)
rows, err := db.Raw(C.SELECT_DISTINCT_MASTER_TYPES).Rows()
if err == nil {
defer rows.Close()
for rows.Next() {
var master models.MasterType
db.ScanRows(rows, &master)
results = append(results, []string{master.Master_Type, master.Master_Type})
}
} else {
logs.GetLogger().Error("Error while getting distinct master_type from master_types table. %s", err)
errors.New("Error while getting distinct master_type from master_types table.")
}
return results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment