feat: new models, sorting fix

This commit is contained in:
2025-03-15 21:12:15 +07:00
parent db7076182e
commit 2b8df155d3
103 changed files with 16214 additions and 4048 deletions

View File

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