2024-02-11 10:56:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-15 22:47:56 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/config"
|
2024-02-11 10:56:21 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/models"
|
2024-02-15 22:47:56 +00:00
|
|
|
"gorm.io/driver/sqlite"
|
2024-02-11 10:56:21 +00:00
|
|
|
"gorm.io/gen"
|
2024-02-15 22:47:56 +00:00
|
|
|
"gorm.io/gorm"
|
2024-02-11 10:56:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-19 09:09:30 +00:00
|
|
|
config := config.NewServerConfig()
|
2024-02-12 08:25:11 +00:00
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
|
2024-02-15 22:47:56 +00:00
|
|
|
db, err := gorm.Open(sqlite.Open(config.DatabasePath), &gorm.Config{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
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-16 12:07:29 +00:00
|
|
|
g.ApplyBasic(
|
2024-02-18 21:37:17 +00:00
|
|
|
models.Worker{},
|
2024-02-21 09:06:54 +00:00
|
|
|
models.Healthcheck{},
|
|
|
|
models.HealthcheckHistory{},
|
2024-02-16 12:07:29 +00:00
|
|
|
models.Cronjob{},
|
|
|
|
models.CronjobHistory{},
|
|
|
|
models.OAuth2State{},
|
|
|
|
)
|
2024-02-11 10:56:21 +00:00
|
|
|
|
|
|
|
// Execute the generator
|
|
|
|
g.Execute()
|
|
|
|
}
|