Example #1
0
func (a *Controller) KendoGridFilter(parent string) *dbs.QE {
	input := a.Ctx.Input
	logic := input.Query(parent + "[logic]")
	//fmt.Printf("Filter for %s logic: %s \n", parent, logic)
	//--- has subfilters
	if logic == "" {
		field := strings.ToLower(input.Query(parent + "[field]"))
		if field == "id" {
			field = "_id"
		}
		op := input.Query(parent + "[operator]")
		value := input.Query(parent + "[value]")
		//fmt.Printf("Op: %v Value: %v\n", op, value)
		if op == "eq" {
			return dbs.Eq(field, value)
		} else if op == "contains" {
			return dbs.Contains(field, value)
		} else if op == "notcontains" {
			return dbs.Contains(field, value)
		} else if op == "startswith" {
			return dbs.StartWith(field, value)
		} else if op == "endswith" {
			return dbs.EndWith(field, value)
		} else {
			return nil
		}
	} else {
		filters := []*dbs.QE{}
		iChild := 0
		var qeFilter *dbs.QE
		filterOk := true
		for valid := filterOk; valid == true; valid = filterOk {
			qeFilter = a.KendoGridFilter(fmt.Sprintf("%s[filters][%d]", parent, iChild))
			if qeFilter != nil {
				filters = append(filters, qeFilter)
			} else {
				filterOk = false
			}
			iChild++
			//fmt.Printf("Filter for %s qe: %s  valid:%v \n", parent, toolkit.JsonString(qeFilter), filterOk)
		}

		//fmt.Printf("Filter done %v\n", toolkit.JsonString(filters))
		if logic == "or" {
			return dbs.Or(filters...)
		} else {
			return dbs.And(filters...)
		}
	}

	return nil
}
Example #2
0
func testSelectFromWhereOrder() {
	q := conn.Query().
		SetStringSign("'").
		Select("customerid", "companyname").
		From("customers").
		Where(
			base.Or(
				base.Eq("customerid", "@1"),
				base.Eq("customerid", "@2"),
				base.And(
					base.Eq("customerid", "@3"),
					base.Eq("companyname", "@4"))),
			base.Contains("companyname", "@5"),
			base.StartWith("companyname", "@6"),
			base.EndWith("companyname", "@7")).
		OrderBy("companyname asc", "customerid desc")
	c := q.Cursor(toolkit.M{
		"@1": "ANATR",
		"@2": "ANTON",
		"@3": "ALFKI",
		"@4": "Alfreds Futterkiste",
		"@5": "freds",
		"@6": "Alfreds",
		"@7": "Futterkiste",
	})
	r := []toolkit.M{}
	e := c.FetchAll(&r, true)

	if e != nil {
		fmt.Println(e.Error())
	}

	fmt.Println("============== QUERY TEST SELECT-FROM-WHERE-ORDERBY")
	fmt.Println(c.GetQueryString())

	for _, each := range r {
		fmt.Println(each)
	}
}