Skip to content

Commit 2529ca9

Browse files
committed
chore: update gen files
1 parent af12612 commit 2529ca9

File tree

7 files changed

+82
-82
lines changed

7 files changed

+82
-82
lines changed

cmd/generate/generate.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"github.com/0xJacky/Nginx-UI/server/model"
7+
"github.com/0xJacky/Nginx-UI/server/settings"
8+
"gorm.io/driver/sqlite"
9+
"gorm.io/gen"
10+
"gorm.io/gorm"
11+
"gorm.io/gorm/logger"
12+
"log"
13+
"path"
14+
)
15+
16+
func main() {
17+
// specify the output directory (default: "./query")
18+
// ### if you want to query without context constrain, set mode gen.WithoutContext ###
19+
g := gen.NewGenerator(gen.Config{
20+
OutPath: "../../server/query",
21+
Mode: gen.WithoutContext | gen.WithDefaultQuery,
22+
//if you want the nullable field generation property to be pointer type, set FieldNullable true
23+
FieldNullable: true,
24+
//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
25+
FieldCoverable: true,
26+
// if you want to generate field with unsigned integer type, set FieldSignable true
27+
/* FieldSignable: true,*/
28+
//if you want to generate index tags from database, set FieldWithIndexTag true
29+
/* FieldWithIndexTag: true,*/
30+
//if you want to generate type tags from database, set FieldWithTypeTag true
31+
/* FieldWithTypeTag: true,*/
32+
//if you need unit tests for query code, set WithUnitTest true
33+
/* WithUnitTest: true, */
34+
})
35+
36+
// reuse the database connection in Project or create a connection here
37+
// if you want to use GenerateModel/GenerateModelAs, UseDB is necessary or it will panic
38+
var confPath string
39+
flag.StringVar(&confPath, "config", "app.ini", "Specify the configuration file")
40+
flag.Parse()
41+
42+
settings.Init(confPath)
43+
dbPath := path.Join(path.Dir(settings.ConfPath), fmt.Sprintf("%s.db", settings.ServerSettings.Database))
44+
45+
var err error
46+
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
47+
Logger: logger.Default.LogMode(logger.Info),
48+
PrepareStmt: true,
49+
DisableForeignKeyConstraintWhenMigrating: true,
50+
})
51+
52+
if err != nil {
53+
log.Fatalln(err)
54+
}
55+
56+
g.UseDB(db)
57+
58+
// apply basic crud api on structs or table models which is specified by table name with function
59+
// GenerateModel/GenerateModelAs. And generator will generate table models' code when calling Excute.
60+
g.ApplyBasic(model.GenerateAllModel()...)
61+
62+
// apply diy interfaces on structs or table models
63+
g.ApplyInterface(func(method model.Method) {}, model.GenerateAllModel()...)
64+
65+
// execute the action of code generation
66+
g.Execute()
67+
}

server/cmd/generate/generate.go

Lines changed: 0 additions & 67 deletions
This file was deleted.

server/query/auths.gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/query/certs.gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/query/config_backups.gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/query/dns_credentials.gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/query/sites.gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)