fix: gen code generator; some unit tests

This commit is contained in:
Jacky 2024-10-22 17:27:40 +08:00
parent 33a996e777
commit 918f920d57
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
8 changed files with 86 additions and 178 deletions

View file

@ -4,7 +4,7 @@ import (
"flag"
"fmt"
"github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/settings"
"github.com/uozi-tech/cosy/settings"
"gorm.io/driver/sqlite"
"gorm.io/gen"
"gorm.io/gorm"
@ -21,26 +21,26 @@ func main() {
Mode: gen.WithoutContext | gen.WithDefaultQuery,
//if you want the nullable field generation property to be pointer type, set FieldNullable true
FieldNullable: true,
//if you want to assign field which has default value in `Create` API, set FieldCoverable true, reference: https://gorm.io/docs/create.html#Default-Values
//if you want to assign field which has the default value in `Create` API, set FieldCoverable true, reference: https://gorm.io/docs/create.html#Default-Values
FieldCoverable: true,
// if you want to generate field with unsigned integer type, set FieldSignable true
// if you want to generate field with an unsigned integer type, set FieldSignable true
/* FieldSignable: true,*/
//if you want to generate index tags from database, set FieldWithIndexTag true
//if you want to generate index tags from the database, set FieldWithIndexTag true
/* FieldWithIndexTag: true,*/
//if you want to generate type tags from database, set FieldWithTypeTag true
//if you want to generate type tags from the database, set FieldWithTypeTag true
/* FieldWithTypeTag: true,*/
//if you need unit tests for query code, set WithUnitTest true
/* WithUnitTest: true, */
})
// reuse the database connection in Project or create a connection here
// if you want to use GenerateModel/GenerateModelAs, UseDB is necessary or it will panic
// if you want to use GenerateModel/GenerateModelAs, UseDB is necessary, or it will panic
var confPath string
flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
flag.Parse()
settings.Init(confPath)
dbPath := path.Join(path.Dir(settings.ConfPath), fmt.Sprintf("%s.db", settings.ServerSettings.Database))
dbPath := path.Join(path.Dir(confPath), fmt.Sprintf("%s.db", settings.DataBaseSettings.Name))
var err error
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
@ -56,7 +56,7 @@ func main() {
g.UseDB(db)
// apply basic crud api on structs or table models which is specified by table name with function
// GenerateModel/GenerateModelAs. And generator will generate table models' code when calling Excute.
// GenerateModel/GenerateModelAs. And the generator will generate table models' code when calling Excute.
g.ApplyBasic(model.GenerateAllModel()...)
// apply diy interfaces on structs or table models