示例#1
0
func DeleteSqlTest() {
	sb := petadb.NewSqlBuilder()

	sb.Where("UserId = @0", 1)
	row, err := database.DeleteSql(&UserInfo{}, &sb)
	if err != nil {
		panic(err)
	}
	fmt.Println(row)
}
示例#2
0
func FindOneTest4() {
	sb := petadb.NewSqlBuilder()
	sb.Where("UserName = @0", "gejin")
	sb.Where("UserId = @0", 12)

	var userInfo UserInfo
	isExists, err := database.FindOneSql(&userInfo, &sb)
	if err != nil {
		panic(err)
	}

	fmt.Println(isExists)
	if isExists {
		fmt.Println(userInfo)
	}
}
示例#3
0
func FindListSqlTest() {
	sb := petadb.NewSqlBuilder()

	sb.Where("UserId > @0", 1)
	sb.Where("CreateDate < @0", time.Now())
	// 当有多个查询条件时,Sql组装是一件非常痛苦的事情
	// sqlBuilder应运而生,多个查询下,简单的sql.Where即可完全应对

	var userList []UserInfo
	// 什么? 不需要写select ... from ??
	// 对,不需要,组件会自动帮你匹配
	err := database.FindListSql(&userList, &sb)
	if err != nil {
		panic(err)
	}

	fmt.Println(userList)
}