Example #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
}
Example #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
}
Example #3
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)
	}
}
Example #4
0
func testDelete() {
	c, _, e := conn.Query().
		SetStringSign("'").
		Delete().
		From("tb_post").
		Where(base.Eq("id", "@id")).
		Run(toolkit.M{"@id": 377})

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

	fmt.Println("============== QUERY TEST UPDATE-FROM-SET-WHERE")
	fmt.Println(c.GetQueryString())
}
Example #5
0
func testUpdate() {
	c, _, e := conn.Query().
		SetStringSign("'").
		Update().
		From("tb_post").
		Where(base.Eq("id", "@id")).
		Run(toolkit.M{"data": toolkit.M{"title": "keyboard", "category": "cinta"}, "@id": 377})

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

	fmt.Println("============== QUERY TEST UPDATE-FROM-SET-WHERE")
	fmt.Println(c.GetQueryString())
}
Example #6
0
func testUpdate() {
	c, _, e := conn.Query().
		SetStringSign("'").
		Update().
		From("customers").
		Where(base.Eq("customerid", "@id")).
		Run(toolkit.M{"data": toolkit.M{"companyname": "nokia sidoarjo"}, "@id": "nokia"})

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

	fmt.Println("============== QUERY TEST UPDATE-FROM-SET-WHERE")
	fmt.Println(c.GetQueryString())
}