本文整理汇总了Golang中github.com/klenin/orc/db.Query函数的典型用法代码示例。如果您正苦于以下问题:Golang Query函数的具体用法?Golang Query怎么用?Golang Query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Query函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Delete
func (*GroupRegistrationsModel) Delete(id int) {
// TODO: TT
query := `with TT AS (
DELETE
FROM registrations
WHERE registrations.id in (
SELECT rs_gs.reg_id
FROM regs_groupregs rs_gs
WHERE rs_gs.groupreg_id = $1
AND array_length(array(
SELECT regs_groupregs.groupreg_id
FROM regs_groupregs
WHERE regs_groupregs.reg_id = rs_gs.reg_id
), 1) = 1
) returning registrations.id
)
DELETE FROM param_values WHERE param_values.reg_id in (
SELECT rs_gs.reg_id
FROM regs_groupregs rs_gs
WHERE rs_gs.groupreg_id = $1
AND array_length(array(
SELECT regs_groupregs.groupreg_id
FROM regs_groupregs
WHERE regs_groupregs.reg_id = rs_gs.reg_id
), 1) = 1
);`
db.Query(query, []interface{}{id})
query = `DELETE FROM group_registrations WHERE id = $1;`
db.Query(query, []interface{}{id})
}
开发者ID:FooBarrior,项目名称:orc,代码行数:31,代码来源:group_registrations.go
示例2: Select_
func (this *Entity) Select_(fields []string) []interface{} {
query := "SELECT %s FROM %s"
if len(this.wherePart) != 0 {
where, params := this.GenerateWherePart(1)
params = append(params, this.orderBy)
query += " WHERE %s ORDER BY $" + strconv.Itoa(len(params))
switch this.limit.(type) {
case string:
query += " LIMIT ALL"
break
case int:
query += " LIMIT $" + strconv.Itoa(len(params))
params = append(params, this.limit)
break
default:
panic("Invalid type of limit")
}
params = append(params, this.offset)
query += " OFFSET $" + strconv.Itoa(len(params)) + ";"
return db.Query(fmt.Sprintf(query, strings.Join(fields, ", "), this.tableName, where), params)
} else {
query += " ORDER BY $1 LIMIT $2 OFFSET $3;"
return db.Query(
fmt.Sprintf(query, strings.Join(fields, ", "), this.tableName),
[]interface{}{this.GetOrder(), this.GetLimit(), this.GetOffset()})
}
}
开发者ID:FooBarrior,项目名称:orc,代码行数:31,代码来源:entity.go
示例3: Delete
func (*GroupsModel) Delete(id int) {
query := `DELETE
FROM persons
WHERE persons.group_id = $1;`
db.Query(query, []interface{}{id})
query = `DELETE FROM groups WHERE id = $1;`
db.Query(query, []interface{}{id})
}
开发者ID:FooBarrior,项目名称:orc,代码行数:9,代码来源:groups.go
示例4: GetColModel
func (*FacesModel) GetColModel(isAdmin bool, userId int) []map[string]interface{} {
query := `SELECT array_to_string(
array(SELECT users.id || ':' || users.login FROM users GROUP BY users.id ORDER BY users.id), ';') as name;`
logins := db.Query(query, nil)[0].(map[string]interface{})["name"].(string)
query = `SELECT array_to_string(
array(
SELECT f.id || ':' || f.id || '-' || array_to_string(
array(
SELECT param_values.value
FROM param_values
INNER JOIN registrations ON registrations.id = param_values.reg_id
INNER JOIN faces ON faces.id = registrations.face_id
INNER JOIN events ON events.id = registrations.event_id
INNER JOIN params ON params.id = param_values.param_id
WHERE param_values.param_id IN (5, 6, 7) AND events.id = 1 AND faces.id = f.id ORDER BY param_values.param_id
), ' ')
FROM param_values
INNER JOIN registrations as reg ON reg.id = param_values.reg_id
INNER JOIN faces as f ON f.id = reg.face_id
INNER JOIN events ON events.id = reg.event_id
INNER JOIN params as p ON p.id = param_values.param_id
INNER JOIN users ON users.id = f.user_id GROUP BY f.id ORDER BY f.id
), ';') as name;`
faces := db.Query(query, nil)[0].(map[string]interface{})["name"].(string)
return []map[string]interface{}{
0: map[string]interface{}{
"index": "id",
"name": "id",
"editable": false,
"formatter": "select",
"edittype": "select",
"stype": "select",
"search": true,
"editoptions": map[string]string{"value": faces},
"searchoptions": map[string]string{"value": ":Все;" + faces},
},
1: map[string]interface{}{
"index": "user_id",
"name": "user_id",
"editable": true,
"formatter": "select",
"edittype": "select",
"stype": "select",
"search": true,
"editrules": map[string]interface{}{"required": true},
"editoptions": map[string]string{"value": logins},
"searchoptions": map[string]string{"value": ":Все;" + logins},
},
}
}
开发者ID:FooBarrior,项目名称:orc,代码行数:53,代码来源:faces.go
示例5: GroupsLoad
func (this *Handler) GroupsLoad() {
userId, err := this.CheckSid()
if err != nil {
http.Error(this.Response, "Unauthorized", 400)
return
}
limit, err := strconv.Atoi(this.Request.PostFormValue("rows"))
if err != nil {
http.Error(this.Response, err.Error(), 400)
return
}
page, err := strconv.Atoi(this.Request.PostFormValue("page"))
if err != nil {
http.Error(this.Response, err.Error(), 400)
return
}
sidx := this.Request.FormValue("sidx")
start := limit*page - limit
query := `SELECT groups.id, groups.name, groups.face_id
FROM groups
INNER JOIN persons ON persons.group_id = groups.id
INNER JOIN faces ON faces.id = persons.face_id
INNER JOIN users ON users.id = faces.user_id
WHERE users.id = $1 ORDER BY $2 LIMIT $3 OFFSET $4;`
rows := db.Query(query, []interface{}{userId, sidx, limit, start})
query = `SELECT COUNT(*) FROM (SELECT groups.id FROM groups
INNER JOIN persons ON persons.group_id = groups.id
INNER JOIN faces ON faces.id = persons.face_id
INNER JOIN users ON users.id = faces.user_id
WHERE users.id = $1) as count;`
count := int(db.Query(query, []interface{}{userId})[0].(map[string]interface{})["count"].(int))
var totalPages int
if count > 0 {
totalPages = int(math.Ceil(float64(count) / float64(limit)))
} else {
totalPages = 0
}
result := make(map[string]interface{}, 2)
result["rows"] = rows
result["page"] = page
result["total"] = totalPages
result["records"] = count
utils.SendJSReply(result, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:52,代码来源:load.go
示例6: GetColModel
func (*GroupRegistrationsModel) GetColModel(isAdmin bool, userId int) []map[string]interface{} {
query := `SELECT array_to_string(
array(SELECT events.id || ':' || events.name FROM events GROUP BY events.id ORDER BY events.id), ';') as name;`
events := db.Query(query, nil)[0].(map[string]interface{})["name"].(string)
query = `SELECT array_to_string(
array(SELECT groups.id || ':' || groups.name FROM groups GROUP BY groups.id ORDER BY groups), ';') as name;`
groups := db.Query(query, nil)[0].(map[string]interface{})["name"].(string)
return []map[string]interface{}{
0: map[string]interface{}{
"index": "id",
"name": "id",
"editable": false,
},
1: map[string]interface{}{
"index": "event_id",
"name": "event_id",
"editable": true,
"formatter": "select",
"edittype": "select",
"stype": "select",
"search": true,
"editrules": map[string]interface{}{"required": true},
"editoptions": map[string]string{"value": events},
"searchoptions": map[string]string{"value": ":Все;" + events},
},
2: map[string]interface{}{
"index": "group_id",
"name": "group_id",
"editable": true,
"formatter": "select",
"edittype": "select",
"stype": "select",
"search": true,
"editrules": map[string]interface{}{"required": true},
"editoptions": map[string]string{"value": groups},
"searchoptions": map[string]string{"value": ":Все;" + groups},
},
3: map[string]interface{}{
"index": "status",
"name": "status",
"editable": true,
"editrules": map[string]interface{}{"required": true},
"formatter": "checkbox",
"formatoptions": map[string]interface{}{"disabled": true},
"edittype": "checkbox",
"editoptions": map[string]interface{}{"value": "true:false"},
},
}
}
开发者ID:FooBarrior,项目名称:orc,代码行数:51,代码来源:group_registrations.go
示例7: Delete
func (*RegistrationsModel) Delete(id int) {
query := `DELETE FROM param_values WHERE param_values.reg_id = $1;`
db.Query(query, []interface{}{id})
// query = `DELETE
// FROM faces
// WHERE faces.id in
// (SELECT registrations.face_id
// FROM registrations WHERE registrations.id = $1);`
// db.Query(query, []interface{}{id})
query = `DELETE FROM registrations WHERE id = $1;`
db.Query(query, []interface{}{id})
}
开发者ID:FooBarrior,项目名称:orc,代码行数:14,代码来源:registrations.go
示例8: Select
func (this *Entity) Select(fields []string, filters map[string]interface{}) (result []interface{}) {
if len(fields) == 0 {
return nil
}
where, params, _ := this.Where(filters, 1)
if where != "" {
where = " WHERE " + where
}
query := `SELECT ` + strings.Join(fields, ", ") + ` FROM ` + this.GetTableName() + where
query += ` ORDER BY ` + this.GetTableName() + "." + this.orderBy
query += ` ` + this.sorting
switch this.limit.(type) {
case string:
query += " LIMIT ALL"
break
case int:
query += " LIMIT $" + strconv.Itoa(len(params))
params = append(params, this.GetLimit())
break
default:
panic("Invalid type of limit")
}
params = append(params, this.GetOffset())
query += ` OFFSET $` + strconv.Itoa(len(params)) + `;`
return db.Query(query, params)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:30,代码来源:entity.go
示例9: Select
func (this *FacesModel) Select(fields []string, filters map[string]interface{}) (result []interface{}) {
if len(fields) == 0 {
return nil
}
query := `SELECT `
for _, field := range fields {
switch field {
case "id":
query += "faces.id, "
break
case "user_id":
query += "users.login, "
break
}
}
query = query[:len(query)-2]
query += ` FROM faces INNER JOIN users ON users.id = faces.user_id`
where, params, _ := this.Where(filters, 1)
if where != "" {
query += ` WHERE ` + where
}
query += ` ORDER BY faces.` + this.orderBy
query += ` ` + this.GetSorting()
params = append(params, this.GetLimit())
query += ` LIMIT $` + strconv.Itoa(len(params))
params = append(params, this.GetOffset())
query += ` OFFSET $` + strconv.Itoa(len(params)) + `;`
return db.Query(query, params)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:33,代码来源:faces.go
示例10: GroupRegistrationsLoad
func (this *Handler) GroupRegistrationsLoad() {
userId, err := this.CheckSid()
if err != nil {
http.Error(this.Response, "Unauthorized", 400)
return
}
limit, err := strconv.Atoi(this.Request.PostFormValue("rows"))
if err != nil {
http.Error(this.Response, err.Error(), 400)
return
}
page, err := strconv.Atoi(this.Request.PostFormValue("page"))
if err != nil {
http.Error(this.Response, err.Error(), 400)
return
}
sidx := this.Request.FormValue("sidx")
start := limit*page - limit
query := `SELECT group_registrations.id, group_registrations.event_id,
group_registrations.group_id
FROM group_registrations
INNER JOIN events ON events.id = group_registrations.event_id
INNER JOIN groups ON groups.id = group_registrations.group_id
INNER JOIN persons ON persons.group_id = groups.id
INNER JOIN faces ON faces.id = persons.face_id
INNER JOIN users ON users.id = faces.user_id
WHERE users.id = $1 AND events.team = $2 ORDER BY $3 LIMIT $4 OFFSET $5;`
rows := db.Query(query, []interface{}{userId, true, sidx, limit, start})
query = `SELECT COUNT(*) FROM (SELECT group_registrations.id
FROM group_registrations
INNER JOIN events ON events.id = group_registrations.event_id
INNER JOIN groups ON groups.id = group_registrations.group_id
INNER JOIN persons ON persons.group_id = groups.id
INNER JOIN faces ON faces.id = persons.face_id
INNER JOIN users ON users.id = faces.user_id
WHERE users.id = $1 AND events.team = $2 GROUP BY group_registrations.id) as count;`
var count int
db.QueryRow(query, []interface{}{userId, true}).Scan(&count)
var totalPages int
if count > 0 {
totalPages = int(math.Ceil(float64(count) / float64(limit)))
} else {
totalPages = 0
}
result := make(map[string]interface{}, 2)
result["rows"] = rows
result["page"] = page
result["total"] = totalPages
result["records"] = count
utils.SendJSReply(result, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:60,代码来源:load.go
示例11: GetHistoryRequest
func (this *BlankController) GetHistoryRequest() {
userId, err := this.CheckSid()
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": "Unauthorized"}, this.Response)
return
}
data, err := utils.ParseJS(this.Request, this.Response)
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
return
}
eventId, err := strconv.Atoi(data["event_id"].(string))
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
return
}
query := `SELECT params.id as param_id, params.name as param_name,
param_types.name as type, param_values.value, forms.id as form_id
FROM events
INNER JOIN events_forms ON events_forms.event_id = events.id
INNER JOIN forms ON events_forms.form_id = forms.id
INNER JOIN registrations ON events.id = registrations.event_id
INNER JOIN faces ON faces.id = registrations.face_id
INNER JOIN users ON users.id = faces.user_id
INNER JOIN params ON params.form_id = forms.id
INNER JOIN param_types ON param_types.id = params.param_type_id
INNER JOIN param_values ON param_values.param_id = params.id
AND param_values.reg_id = registrations.id
WHERE users.id = $1 AND events.id = $2 AND forms.personal = true;`
utils.SendJSReply(map[string]interface{}{"result": "ok", "data": db.Query(query, []interface{}{userId, eventId})}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:35,代码来源:blank_controller.go
示例12: GetEventTypesByEventId
//-----------------------------------------------------------------------------
func (this *GridController) GetEventTypesByEventId() {
if !sessions.CheckSession(this.Response, this.Request) {
http.Redirect(this.Response, this.Request, "/", http.StatusUnauthorized)
return
}
if !this.isAdmin() {
http.Redirect(this.Response, this.Request, "/", http.StatusForbidden)
return
}
request, err := utils.ParseJS(this.Request, this.Response)
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
return
}
eventId, err := strconv.Atoi(request["event_id"].(string))
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
return
}
query := `SELECT event_types.id, event_types.name FROM events_types
INNER JOIN events ON events.id = events_types.event_id
INNER JOIN event_types ON event_types.id = events_types.type_id
WHERE events.id = $1 ORDER BY event_types.id;`
result := db.Query(query, []interface{}{eventId})
utils.SendJSReply(map[string]interface{}{"result": "ok", "data": result}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:36,代码来源:grid_controller.go
示例13: GetListHistoryEvents
func (this *BlankController) GetListHistoryEvents() {
userId, err := this.CheckSid()
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": "Unauthorized"}, this.Response)
return
}
data, err := utils.ParseJS(this.Request, this.Response)
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
return
}
ids := map[string]interface{}{"form_id": make([]interface{}, 0)}
if data["form_ids"] == nil || len(data["form_ids"].([]interface{})) == 0 {
utils.SendJSReply(map[string]interface{}{"result": "Нет данных о формах анкеты"}, this.Response)
return
}
for _, v := range data["form_ids"].([]interface{}) {
ids["form_id"] = append(ids["form_id"].([]interface{}), int(v.(float64)))
}
eventsForms := this.GetModel("events_forms")
events := eventsForms.
LoadWherePart(ids).
SetCondition(models.OR).
Select_([]string{"event_id"})
if len(events) == 0 {
utils.SendJSReply(map[string]interface{}{"result": "Нет данных"}, this.Response)
return
}
query := `SELECT DISTINCT events.id, events.name FROM events
INNER JOIN events_forms ON events_forms.event_id = events.id
INNER JOIN forms ON events_forms.form_id = forms.id
INNER JOIN registrations ON registrations.event_id = events.id
INNER JOIN faces ON faces.id = registrations.face_id
INNER JOIN users ON users.id = faces.user_id
WHERE users.id=$1 AND events.id IN (`
var i int
params := []interface{}{userId}
for i = 2; i < len(events); i++ {
query += "$" + strconv.Itoa(i) + ", "
params = append(params, int(events[i-2].(map[string]interface{})["event_id"].(int)))
}
query += "$" + strconv.Itoa(i) + ")"
params = append(params, int(events[i-2].(map[string]interface{})["event_id"].(int)))
utils.SendJSReply(map[string]interface{}{"result": "ok", "data": db.Query(query, params)}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:59,代码来源:blank_controller.go
示例14: generateUsers
func generateUsers(count int) {
base := new(controllers.BaseController)
date := time.Now().Format("2006-01-02T15:04:05Z00:00")
type FullNames struct {
firstNames, lastNames, patronymics []string
}
male := FullNames{
firstNames: readStringsFromFile(getResourcePath("first-name-male.txt")),
lastNames: readStringsFromFile(getResourcePath("last-name-male.txt")),
patronymics: readStringsFromFile(getResourcePath("patronymic-male.txt")),
}
female := FullNames{
firstNames: readStringsFromFile(getResourcePath("first-name-female.txt")),
lastNames: readStringsFromFile(getResourcePath("last-name-female.txt")),
patronymics: readStringsFromFile(getResourcePath("patronymic-female.txt")),
}
for i := 0; i < count; i++ {
userName := "user" + strconv.Itoa(i+1)
userEmail := userName + "@example.com"
result, regId := base.RegistrationController().Register(userName, "password", userEmail, "user")
if result != "ok" {
log.Fatalln("[loadUsers]:", result)
}
query := `INSERT INTO param_values (param_id, value, date, reg_id)
VALUES ($1, $2, $3, $4);`
db.Exec(query, []interface{}{4, userEmail, date, regId})
var fullNames FullNames
if rand.Int()%2 == 1 {
fullNames = male
} else {
fullNames = female
}
db.Exec(query, []interface{}{6, fullNames.firstNames[rand.Intn(len(fullNames.firstNames))], date, regId})
db.Exec(query, []interface{}{5, fullNames.lastNames[rand.Intn(len(fullNames.lastNames))], date, regId})
db.Exec(query, []interface{}{7, fullNames.patronymics[rand.Intn(len(fullNames.patronymics))], date, regId})
query = `SELECT users.token FROM registrations
INNER JOIN events ON registrations.event_id = events.id
INNER JOIN faces ON faces.id = registrations.face_id
INNER JOIN users ON users.id = faces.user_id
WHERE events.id = $1 AND registrations.id = $2;`
res := db.Query(query, []interface{}{1, regId})
if len(res) == 0 {
log.Fatalln("[loadUsers]:", "Data are not found")
}
token := res[0].(map[string]interface{})["token"].(string)
base.RegistrationController().ConfirmUser(token)
}
}
开发者ID:klenin,项目名称:orc,代码行数:57,代码来源:user.go
示例15: InsertUserParams
func (this *RegistrationController) InsertUserParams(userId, regId int, data []interface{}) (err error) {
var paramValueIds []string
date := time.Now().Format("2006-01-02T15:04:05Z00:00")
for _, element := range data {
paramId, err := strconv.Atoi(element.(map[string]interface{})["id"].(string))
if err != nil {
continue
}
if paramId == 1 || paramId == 2 || paramId == 3 {
continue
}
query := `SELECT params.name, params.required, params.editable
FROM params
WHERE params.id = $1;`
result := db.Query(query, []interface{}{paramId})
name := result[0].(map[string]interface{})["name"].(string)
required := result[0].(map[string]interface{})["required"].(bool)
editable := result[0].(map[string]interface{})["editable"].(bool)
value := element.(map[string]interface{})["value"].(string)
if required && utils.MatchRegexp("^[ \t\v\r\n\f]{0,}$", value) {
db.QueryDeleteByIds("param_vals", strings.Join(paramValueIds, ", "))
db.QueryDeleteByIds("registrations", strconv.Itoa(regId))
return errors.New("Заполните параметр '" + name + "'.")
}
if !editable {
value = " "
}
var paramValId int
err = this.GetModel("param_values").
LoadModelData(map[string]interface{}{
"param_id": paramId,
"value": value,
"date": date,
"user_id": userId,
"reg_id": regId}).
QueryInsert("RETURNING id").
Scan(¶mValId)
if err, ok := err.(*pq.Error); ok {
log.Println(err.Code.Name())
}
paramValueIds = append(paramValueIds, strconv.Itoa(paramValId))
}
return nil
}
开发者ID:FooBarrior,项目名称:orc,代码行数:55,代码来源:registration_controller.go
示例16: GetColModel
func (*RegsGroupRegsModel) GetColModel(isAdmin bool, userId int) []map[string]interface{} {
query := `SELECT array_to_string(
array(SELECT group_registrations.id || ':' || group_registrations.id FROM group_registrations GROUP BY group_registrations.id ORDER BY group_registrations.id), ';') as name;`
groupRegs := db.Query(query, nil)[0].(map[string]interface{})["name"].(string)
query = `SELECT array_to_string(
array(SELECT registrations.id || ':' || registrations.id FROM registrations GROUP BY registrations.id ORDER BY registrations.id), ';') as name;`
regs := db.Query(query, nil)[0].(map[string]interface{})["name"].(string)
return []map[string]interface{}{
0: map[string]interface{}{
"index": "id",
"name": "id",
"editable": false,
},
1: map[string]interface{}{
"index": "groupreg_id",
"name": "groupreg_id",
"editable": true,
"formatter": "select",
"edittype": "select",
"stype": "select",
"search": true,
"editrules": map[string]interface{}{"required": true},
"editoptions": map[string]string{"value": groupRegs},
"searchoptions": map[string]string{"value": ":Все;" + groupRegs},
},
2: map[string]interface{}{
"index": "reg_id",
"name": "reg_id",
"editable": true,
"formatter": "select",
"edittype": "select",
"stype": "select",
"search": true,
"editrules": map[string]interface{}{"required": true},
"editoptions": map[string]string{"value": regs},
"searchoptions": map[string]string{"value": ":Все;" + regs},
},
}
}
开发者ID:FooBarrior,项目名称:orc,代码行数:41,代码来源:regs_groupregs.go
示例17: GetColModel
func (*EventsTypesModel) GetColModel(isAdmin bool, userId int) []map[string]interface{} {
query := `SELECT array_to_string(
array(SELECT events.id || ':' || events.name FROM events GROUP BY events.id ORDER BY events.id), ';') as name;`
events := db.Query(query, nil)[0].(map[string]interface{})["name"].(string)
query = `SELECT array_to_string(
array(SELECT event_types.id || ':' || event_types.name FROM event_types GROUP BY event_types.id ORDER BY event_types.id), ';') as name;`
types := db.Query(query, nil)[0].(map[string]interface{})["name"].(string)
return []map[string]interface{}{
0: map[string]interface{}{
"index": "id",
"name": "id",
"editable": false,
},
1: map[string]interface{}{
"index": "event_id",
"name": "event_id",
"editable": true,
"formatter": "select",
"edittype": "select",
"stype": "select",
"search": true,
"editrules": map[string]interface{}{"required": true},
"editoptions": map[string]string{"value": events},
"searchoptions": map[string]string{"value": ":Все;" + events},
},
2: map[string]interface{}{
"index": "type_id",
"name": "type_id",
"editable": true,
"formatter": "select",
"edittype": "select",
"stype": "select",
"search": true,
"editrules": map[string]interface{}{"required": true},
"editoptions": map[string]string{"value": types},
"searchoptions": map[string]string{"value": ":Все;" + types},
},
}
}
开发者ID:FooBarrior,项目名称:orc,代码行数:41,代码来源:events_types.go
示例18: EditParams
//-----------------------------------------------------------------------------
func (this *BlankController) EditParams() {
userId, err := this.CheckSid()
if err != nil {
http.Redirect(this.Response, this.Request, "/", http.StatusUnauthorized)
return
}
request, err := utils.ParseJS(this.Request, this.Response)
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
return
}
date := time.Now().Format("2006-01-02T15:04:05Z00:00")
for _, v := range request["data"].([]interface{}) {
paramValId, err := strconv.Atoi(v.(map[string]interface{})["param_val_id"].(string))
if err != nil {
utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
return
}
query := `SELECT params.name, params.required, params.editable
FROM params
INNER JOIN param_values ON param_values.param_id = params.id
WHERE param_values.id = $1;`
result := db.Query(query, []interface{}{paramValId})
name := result[0].(map[string]interface{})["name"].(string)
required := result[0].(map[string]interface{})["required"].(bool)
editable := result[0].(map[string]interface{})["editable"].(bool)
value := v.(map[string]interface{})["value"].(string)
if required && utils.MatchRegexp("^[ \t\v\r\n\f]{0,}$", value) {
utils.SendJSReply(map[string]interface{}{"result": "Заполните параметр '" + name + "'"}, this.Response)
return
}
if !this.isAdmin() && !editable {
continue
}
if value == "" {
value = " "
}
params := map[string]interface{}{"value": value, "date": date, "user_id": userId}
where := map[string]interface{}{"id": paramValId}
this.GetModel("param_values").Update(this.isAdmin(), userId, params, where)
}
utils.SendJSReply(map[string]interface{}{"result": "Изменения сохранены"}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:54,代码来源:blank_controller.go
示例19: Select
func (this *ParamValuesModel) Select(fields []string, filters map[string]interface{}) (result []interface{}) {
if len(fields) == 0 {
return nil
}
query := `SELECT `
for _, field := range fields {
switch field {
case "id":
query += "param_values.id, "
break
case "param_id":
query += "forms.name || ': ' || params.name as name, "
break
case "reg_id":
query += "registrations.id || ' - ' || events.name, "
break
case "value":
query += "param_values.value, "
break
case "date":
query += "param_values.date, "
break
case "user_id":
query += "users.login, "
break
}
}
query = query[:len(query)-2]
query += ` FROM registrations
INNER JOIN param_values ON param_values.reg_id = registrations.id
INNER JOIN params ON params.id = param_values.param_id
INNER JOIN forms ON forms.id = params.form_id
INNER JOIN users ON users.id = param_values.user_id
INNER JOIN events ON events.id = registrations.event_id`
where, params, _ := this.Where(filters, 1)
if where != "" {
where = " WHERE " + where
}
query += ` ORDER BY param_values.` + this.orderBy
query += ` ` + this.GetSorting()
params = append(params, this.GetLimit())
query += ` LIMIT $` + strconv.Itoa(len(params))
params = append(params, this.GetOffset())
query += ` OFFSET $` + strconv.Itoa(len(params)) + ";"
return db.Query(query, params)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:50,代码来源:param_values.go
示例20: GetEmptyBlank
func (this *Blank) GetEmptyBlank(eventId int) []interface{} {
query := `SELECT forms.id as form_id, forms.name as form_name,
params.id as param_id, params.name as param_name, params.required,
params.editable, param_types.name as type, events.name as event_name,
events.id as event_id
FROM events_forms
INNER JOIN events ON events.id = events_forms.event_id
INNER JOIN forms ON forms.id = events_forms.form_id
INNER JOIN params ON forms.id = params.form_id
INNER JOIN param_types ON param_types.id = params.param_type_id
WHERE events.id = $1 AND forms.personal = $2 ORDER BY forms.id, params.id;`
return db.Query(query, []interface{}{eventId, this.personal})
}
开发者ID:FooBarrior,项目名称:orc,代码行数:14,代码来源:blank.go
注:本文中的github.com/klenin/orc/db.Query函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论