aboutsummaryrefslogtreecommitdiff
path: root/cmd/ggen
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-02-26 19:54:48 +0100
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-18 16:30:36 +0200
commitc8e1328164e9ffbd681c3c0e449f1e6b9856b896 (patch)
treefaee639a4c55c5dc3bfc59a5400026822c40221d /cmd/ggen
downloadlens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.gz
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.tar.bz2
lens-c8e1328164e9ffbd681c3c0e449f1e6b9856b896.zip
feat: Inicial commit
It contains rough template for the server and runners. It contains rough template for the server and runners.
Diffstat (limited to 'cmd/ggen')
-rw-r--r--cmd/ggen/main.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/cmd/ggen/main.go b/cmd/ggen/main.go
new file mode 100644
index 0000000..b519739
--- /dev/null
+++ b/cmd/ggen/main.go
@@ -0,0 +1,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()
+}