1package main
2
3import (
4 "github.com/sirupsen/logrus"
5 "gorm.io/driver/sqlite"
6 "gorm.io/gen"
7 "gorm.io/gorm"
8
9 "git.sr.ht/~gabrielgio/img/pkg/database/sql"
10 "git.sr.ht/~gabrielgio/img/pkg/ext"
11)
12
13func main() {
14 cfg := gen.Config{
15 OutPath: "./pkg/database/sql/query",
16 WithUnitTest: true,
17 Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
18 }
19
20 g := gen.NewGenerator(cfg)
21
22 logger := logrus.New()
23 logger.SetLevel(logrus.TraceLevel)
24 d := sqlite.Open("test.db")
25 db, err := gorm.Open(d, &gorm.Config{
26 Logger: ext.Wraplog(logger.WithField("context", "sql")),
27 })
28 if err != nil {
29 panic("failed to gen database: " + err.Error())
30 }
31
32 g.UseDB(db)
33
34 for _, m := range []any{
35 &sql.User{},
36 &sql.Settings{},
37 &sql.Media{},
38 } {
39 g.ApplyBasic(m)
40 }
41
42 g.Execute()
43}