func DeleteSqlTest() { sb := petadb.NewSqlBuilder() sb.Where("UserId = @0", 1) row, err := database.DeleteSql(&UserInfo{}, &sb) if err != nil { panic(err) } fmt.Println(row) }
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) } }
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) }