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