From c5df9a597d10ba4cd9b0f13ffe788f4c70f0728c Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 10 Sep 2025 19:28:50 +0800 Subject: [PATCH] databse provider --- .../project/database/-transform.yaml.raw | 6 +++ templates/project/database/database.go.tpl | 22 ++++++++ templates/project/go.mod.tpl | 51 +++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/templates/project/database/-transform.yaml.raw b/templates/project/database/-transform.yaml.raw index 532b54e..76fc5cc 100755 --- a/templates/project/database/-transform.yaml.raw +++ b/templates/project/database/-transform.yaml.raw @@ -1,5 +1,11 @@ ignores: - migrations +- river_client +- river_client_queue +- river_job +- river_leader +- river_migration +- river_queue imports: - go.ipao.vip/gen field_type: diff --git a/templates/project/database/database.go.tpl b/templates/project/database/database.go.tpl index 573c633..dfa7cd7 100644 --- a/templates/project/database/database.go.tpl +++ b/templates/project/database/database.go.tpl @@ -5,6 +5,14 @@ import ( "database/sql" "embed" "fmt" + + "{{.ModuleName}}/database/models" + + "github.com/rogeecn/atom" + "go.ipao.vip/atom/container/container" + "go.ipao.vip/atom/contracts/contracts" + "go.ipao.vip/atom/opt/opt" + "gorm.io/gorm" ) //go:embed migrations/* @@ -31,3 +39,17 @@ func WrapLikeLeft(v string) string { func WrapLikeRight(v string) string { return "%" + v } + +func Provide(...opt.Option) error { + return container.Container.Provide(func(db *gorm.DB) contracts.Initial { + models.SetDefault(db) + return models.Q + }, atom.GroupInitial) +} + +func DefaultProvider() container.ProviderContainer { + return container.ProviderContainer{ + Provider: Provide, + Options: []opt.Option{}, + } +} diff --git a/templates/project/go.mod.tpl b/templates/project/go.mod.tpl index e797a1e..41d0b41 100755 --- a/templates/project/go.mod.tpl +++ b/templates/project/go.mod.tpl @@ -1,3 +1,54 @@ module {{.ModuleName}} go 1.22.0 + +require ( + github.com/ThreeDotsLabs/watermill v1.5.1 + github.com/ThreeDotsLabs/watermill-kafka/v3 v3.1.1 + github.com/ThreeDotsLabs/watermill-redisstream v1.4.4 + github.com/ThreeDotsLabs/watermill-sql/v3 v3.1.0 + github.com/gofiber/fiber/v3 v3.0.0-rc.1 + github.com/gofiber/utils/v2 v2.0.0-rc.1 + github.com/golang-jwt/jwt/v4 v4.5.2 + github.com/imroc/req/v3 v3.55.0 + github.com/jackc/pgx/v5 v5.7.6 + github.com/juju/go4 v0.0.0-20160222163258-40d72ab9641a + github.com/lib/pq v1.10.9 + github.com/opentracing/opentracing-go v1.2.0 + github.com/pkg/errors v0.9.1 + github.com/pressly/goose/v3 v3.25.0 + github.com/redis/go-redis/v9 v9.13.0 + github.com/riverqueue/river v0.24.0 + github.com/riverqueue/river/riverdriver/riverdatabasesql v0.24.0 + github.com/riverqueue/river/riverdriver/riverpgxv5 v0.24.0 + github.com/riverqueue/river/rivertype v0.24.0 + github.com/rogeecn/fabfile v1.7.0 + github.com/rogeecn/swag v1.0.1 + github.com/samber/lo v1.51.0 + github.com/sirupsen/logrus v1.9.3 + github.com/smartystreets/goconvey v1.8.1 + github.com/soheilhy/cmux v0.1.5 + github.com/speps/go-hashids/v2 v2.0.1 + github.com/spf13/cobra v1.10.1 + github.com/stretchr/testify v1.11.1 + github.com/swaggo/files/v2 v2.0.2 + github.com/uber/jaeger-client-go v2.30.0+incompatible + go.ipao.vip/atom v1.1.8 + go.opentelemetry.io/contrib/instrumentation/runtime v0.63.0 + go.opentelemetry.io/otel v1.38.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.38.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 + go.opentelemetry.io/otel/metric v1.38.0 + go.opentelemetry.io/otel/sdk v1.38.0 + go.opentelemetry.io/otel/sdk/metric v1.38.0 + go.opentelemetry.io/otel/trace v1.38.0 + go.uber.org/dig v1.19.0 + golang.org/x/net v0.44.0 + golang.org/x/sync v0.17.0 + google.golang.org/grpc v1.75.0 + google.golang.org/protobuf v1.36.9 + gopkg.in/retry.v1 v1.0.3 +)