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

147 lines
3.8 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.AppAccount{})
if err != nil {
fmt.Printf("Error: AutoMigrate(&model.AppAccount{}) fail: %s", err)
}
}
func Test_appAccountQuery(t *testing.T) {
appAccount := newAppAccount(_gen_test_db)
appAccount = *appAccount.As(appAccount.TableName())
_do := appAccount.WithContext(context.Background()).Debug()
primaryKey := field.NewString(appAccount.TableName(), clause.PrimaryKey)
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
if err != nil {
t.Error("clean table <app_account> fail:", err)
return
}
_, ok := appAccount.GetFieldByName("")
if ok {
t.Error("GetFieldByName(\"\") from appAccount success")
}
err = _do.Create(&model.AppAccount{})
if err != nil {
t.Error("create item in table <app_account> fail:", err)
}
err = _do.Save(&model.AppAccount{})
if err != nil {
t.Error("create item in table <app_account> fail:", err)
}
err = _do.CreateInBatches([]*model.AppAccount{{}, {}}, 10)
if err != nil {
t.Error("create item in table <app_account> fail:", err)
}
_, err = _do.Select(appAccount.ALL).Take()
if err != nil {
t.Error("Take() on table <app_account> fail:", err)
}
_, err = _do.First()
if err != nil {
t.Error("First() on table <app_account> fail:", err)
}
_, err = _do.Last()
if err != nil {
t.Error("First() on table <app_account> 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_account> fail:", err)
}
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.AppAccount{}, 10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatches() on table <app_account> fail:", err)
}
_, err = _do.Select(appAccount.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
if err != nil {
t.Error("Find() on table <app_account> fail:", err)
}
_, err = _do.Distinct(primaryKey).Take()
if err != nil {
t.Error("select Distinct() on table <app_account> fail:", err)
}
_, err = _do.Select(appAccount.ALL).Omit(primaryKey).Take()
if err != nil {
t.Error("Omit() on table <app_account> fail:", err)
}
_, err = _do.Group(primaryKey).Find()
if err != nil {
t.Error("Group() on table <app_account> 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_account> fail:", err)
}
_, _, err = _do.FindByPage(0, 1)
if err != nil {
t.Error("FindByPage() on table <app_account> fail:", err)
}
_, err = _do.ScanByPage(&model.AppAccount{}, 0, 1)
if err != nil {
t.Error("ScanByPage() on table <app_account> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
if err != nil {
t.Error("FirstOrInit() on table <app_account> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
if err != nil {
t.Error("FirstOrCreate() on table <app_account> 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_account> fail:", err)
}
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("LeftJoin() on table <app_account> fail:", err)
}
_, err = _do.Not().Or().Clauses().Take()
if err != nil {
t.Error("Not/Or/Clauses on table <app_account> fail:", err)
}
}