示例#1
0
//SELECT id, name, password FROM tb_account LIMIT 0, 100;
func ExampleSelectQuery1() {
	a := Account{}
	esql := easysql.SelectFrom("tb_account").Columns("id , name , password", &a.Id, &a.Name, &a.Password).Limit(0, 100)
	query, args, err := esql.Query()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
	fmt.Println(query)
	fmt.Println(args)

	// output:
	// SELECT `id`,`name`,`password` FROM `tb_account` LIMIT ?,?
	// [0 100]
}
示例#2
0
//SELECT COUNT(*) FROM tb_account where status>0 and status<10;
func ExampleSelectQuery2() {
	var count int
	esql := easysql.SelectFrom("tb_account").Functions("COUNT(*)", &count).Where("status>?", 0).AndWhere("status<?", 10)
	query, args, err := esql.Query()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
	fmt.Println(query)
	fmt.Println(args)

	// output:
	// SELECT COUNT(*) FROM `tb_account` WHERE (`status`>?) AND (`status`<?)
	// [0 10]
}