Jollia Dai преди 2 месеца
родител
ревизия
553928429c
променени са 4 файла, в които са добавени 23 реда и са изтрити 11 реда
  1. 2 0
      conf/db.yaml
  2. 1 2
      go.sum
  3. 6 5
      services/config.go
  4. 14 4
      services/gen_service.go

+ 2 - 0
conf/db.yaml

@@ -3,3 +3,5 @@ port: 3308
 user: root
 pwd: ticket@2025
 schema: ticket-cloud-0212
+tables:
+  - request_pos

+ 1 - 2
go.sum

@@ -105,6 +105,5 @@ gorm.io/hints v1.1.0 h1:Lp4z3rxREufSdxn4qmkK3TLDltrM10FLTHiuqwDPvXw=
 gorm.io/hints v1.1.0/go.mod h1:lKQ0JjySsPBj3uslFzY3JhYDtqEwzm+G1hv8rWujB6Y=
 gorm.io/plugin/dbresolver v1.5.0 h1:XVHLxh775eP0CqVh3vcfJtYqja3uFl5Wr3cKlY8jgDY=
 gorm.io/plugin/dbresolver v1.5.0/go.mod h1:l4Cn87EHLEYuqUncpEeTC2tTJQkjngPSD+lo8hIvcT0=
-jollia.cn/jolib/jokode v0.8.8 h1:ff86eQb3r25kAjPAO36SPuGLnuLb7Tufzv5rNPcX8fM=
-jollia.cn/jolib/jokode v0.8.8/go.mod h1:uihUtfL4MHHyIss+gLtS1m/k+VC5K/WzIKRPCqZGovM=
+jollia.cn/jolib/jokode v0.8.9 h1:LZCY2FIporHtHUqhUcxy26q7RxRKKKi1NlyGtX5FQ1Q=
 jollia.cn/jolib/jokode v0.8.9/go.mod h1:uihUtfL4MHHyIss+gLtS1m/k+VC5K/WzIKRPCqZGovM=

+ 6 - 5
services/config.go

@@ -6,11 +6,12 @@ import (
 )
 
 type DbConfig struct {
-	Host   string `json:"host,omitempty" yaml:"host,omitempty"`
-	Port   int    `json:"port,omitempty" yaml:"port,omitempty"`
-	Schema string `json:"schema,omitempty" yaml:"schema,omitempty"`
-	User   string `json:"user,omitempty" yaml:"user,omitempty"`
-	Pwd    string `json:"pwd,omitempty" yaml:"pwd,omitempty"`
+	Host   string   `json:"host,omitempty" yaml:"host,omitempty"`
+	Port   int      `json:"port,omitempty" yaml:"port,omitempty"`
+	Schema string   `json:"schema,omitempty" yaml:"schema,omitempty"`
+	User   string   `json:"user,omitempty" yaml:"user,omitempty"`
+	Pwd    string   `json:"pwd,omitempty" yaml:"pwd,omitempty"`
+	Tables []string `json:"tables,omitempty" yaml:"tables,omitempty"`
 }
 
 var (

+ 14 - 4
services/gen_service.go

@@ -19,6 +19,7 @@ const (
 
 type GenService struct {
 	dbInstance *gorm.DB
+	tables     []string
 }
 
 func (s *GenService) Init() error {
@@ -49,6 +50,9 @@ func (s *GenService) Init() error {
 		return errors.New("load db config returns nil")
 	} else {
 		dbCfg = cfg
+		if len(cfg.Tables) > 0 {
+			s.tables = cfg.Tables
+		}
 	}
 
 	if !dbConfigFlag.IsZero() {
@@ -128,9 +132,7 @@ func (s *GenService) Start() error {
 	}
 
 	g := gen.NewGenerator(gen.Config{
-		//OutPath:           "po",
-		//OutFile:           "po",
-		//ModelPkgPath:      "po",
+		OutPath:           "model",
 		WithUnitTest:      false,
 		FieldNullable:     true,
 		FieldCoverable:    true,
@@ -154,7 +156,15 @@ func (s *GenService) Start() error {
 	})
 
 	g.UseDB(s.dbInstance)
-	g.GenerateAllTable()
+
+	if len(s.tables) > 0 {
+		for _, tableName := range s.tables {
+			g.GenerateModel(tableName)
+		}
+	} else {
+		g.GenerateAllTable()
+	}
+
 	g.Execute()
 
 	return nil