Exemple #1
0
func LoginDo(username string, password string) (*UserModel, bool) {
	ctx, _ := prepareContext()
	defer ctx.Close()

	u := new(UserModel)
	hashPassword := helper.GetMD5Hash(password)
	c := ctx.Find(u, tk.M{"where": base.And(base.Eq("UserName", username), base.Eq("PasswordHash", hashPassword))})

	found, _ := c.FetchClose(u)
	return u, found
}
Exemple #2
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
}
Exemple #3
0
func (a *Controller) KendoGridSettings(ins toolkit.M) toolkit.M {
	if ins == nil {
		ins = toolkit.M{}
	}
	s := toolkit.M{}
	q_skip := a.Ctx.Input.Query("skip")
	q_page := a.Ctx.Input.Query("page")
	q_size := a.Ctx.Input.Query("pageSize")

	if q_skip != "" {
		s.Set("skip", toolkit.ToInt(q_skip))
	}

	if q_page != "" {
		s.Set("page", toolkit.ToInt(q_page))
	}

	if q_size != "" {
		s.Set("limit", toolkit.ToInt(q_size))
	}

	sortField := strings.ToLower(a.Ctx.Input.Query("sort[0][field]"))
	sortDir := a.Ctx.Input.Query("sort[0][dir]")

	if sortField != "" {
		if sortField == "id" {
			sortField = "_id"
		}
		if sortDir == "" || sortDir == "asc" {
			s.Set("order", []string{sortField})
		} else {
			s.Set("order", []string{"-" + sortField})
		}
	}

	if fqe := a.KendoGridFilter("filter"); fqe != nil {
		if ins.Has("where") {
			fqe = dbs.And(fqe, ins.Get("where").(*dbs.QE))
		}
		s.Set("where", fqe)
	}

	return s
}
Exemple #4
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)
	}
}