youtu_ecpm/dao/query/app_user_info.gen_test.go
2025-01-20 00:14:43 +08:00

147 lines
3.9 KiB
Go

// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"fmt"
"testing"
"gitea.youtukeji.com.cn/xiabin/youtu_ecpm/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"
)
func init() {
InitializeDB()
err := _gen_test_db.AutoMigrate(&model.AppUserInfo{})
if err != nil {
fmt.Printf("Error: AutoMigrate(&model.AppUserInfo{}) fail: %s", err)
}
}
func Test_appUserInfoQuery(t *testing.T) {
appUserInfo := newAppUserInfo(_gen_test_db)
appUserInfo = *appUserInfo.As(appUserInfo.TableName())
_do := appUserInfo.WithContext(context.Background()).Debug()
primaryKey := field.NewString(appUserInfo.TableName(), clause.PrimaryKey)
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
if err != nil {
t.Error("clean table <app_user_info> fail:", err)
return
}
_, ok := appUserInfo.GetFieldByName("")
if ok {
t.Error("GetFieldByName(\"\") from appUserInfo success")
}
err = _do.Create(&model.AppUserInfo{})
if err != nil {
t.Error("create item in table <app_user_info> fail:", err)
}
err = _do.Save(&model.AppUserInfo{})
if err != nil {
t.Error("create item in table <app_user_info> fail:", err)
}
err = _do.CreateInBatches([]*model.AppUserInfo{{}, {}}, 10)
if err != nil {
t.Error("create item in table <app_user_info> fail:", err)
}
_, err = _do.Select(appUserInfo.ALL).Take()
if err != nil {
t.Error("Take() on table <app_user_info> fail:", err)
}
_, err = _do.First()
if err != nil {
t.Error("First() on table <app_user_info> fail:", err)
}
_, err = _do.Last()
if err != nil {
t.Error("First() on table <app_user_info> fail:", err)
}
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatch() on table <app_user_info> fail:", err)
}
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.AppUserInfo{}, 10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatches() on table <app_user_info> fail:", err)
}
_, err = _do.Select(appUserInfo.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
if err != nil {
t.Error("Find() on table <app_user_info> fail:", err)
}
_, err = _do.Distinct(primaryKey).Take()
if err != nil {
t.Error("select Distinct() on table <app_user_info> fail:", err)
}
_, err = _do.Select(appUserInfo.ALL).Omit(primaryKey).Take()
if err != nil {
t.Error("Omit() on table <app_user_info> fail:", err)
}
_, err = _do.Group(primaryKey).Find()
if err != nil {
t.Error("Group() on table <app_user_info> fail:", err)
}
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
if err != nil {
t.Error("Scopes() on table <app_user_info> fail:", err)
}
_, _, err = _do.FindByPage(0, 1)
if err != nil {
t.Error("FindByPage() on table <app_user_info> fail:", err)
}
_, err = _do.ScanByPage(&model.AppUserInfo{}, 0, 1)
if err != nil {
t.Error("ScanByPage() on table <app_user_info> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
if err != nil {
t.Error("FirstOrInit() on table <app_user_info> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
if err != nil {
t.Error("FirstOrCreate() on table <app_user_info> fail:", err)
}
var _a _another
var _aPK = field.NewString(_a.TableName(), "id")
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("Join() on table <app_user_info> fail:", err)
}
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("LeftJoin() on table <app_user_info> fail:", err)
}
_, err = _do.Not().Or().Clauses().Take()
if err != nil {
t.Error("Not/Or/Clauses on table <app_user_info> fail:", err)
}
}