zdravko/tools/generate/main.go

31 lines
803 B
Go
Raw Normal View History

2024-02-11 10:56:21 +00:00
package main
import (
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/models"
"gorm.io/gen"
)
func main() {
2024-02-12 08:25:11 +00:00
config := internal.NewConfig()
2024-02-11 10:56:21 +00:00
// Initialize the generator with configuration
g := gen.NewGenerator(gen.Config{
2024-02-11 11:57:57 +00:00
OutPath: "internal/models/query",
2024-02-11 10:56:21 +00:00
Mode: gen.WithDefaultQuery | gen.WithQueryInterface,
FieldNullable: true,
})
db, _, _ := internal.ConnectToDatabase(config.DatabasePath)
2024-02-11 10:56:21 +00:00
// Use the above `*gorm.DB` instance to initialize the generator,
// which is required to generate structs from db when using `GenerateModel/GenerateModelAs`
g.UseDB(db)
// Generate default DAO interface for those specified structs
2024-02-12 08:25:11 +00:00
g.ApplyBasic(models.Healthcheck{}, models.OAuth2State{})
2024-02-11 10:56:21 +00:00
// Execute the generator
g.Execute()
}