improved orm setup

This commit is contained in:
Jean Jacques Avril 2024-11-13 19:09:04 +01:00
parent 1e9ad26db5
commit 3043c83f71
No known key found for this signature in database
13 changed files with 51 additions and 75 deletions

View File

@ -1,11 +1,11 @@
generator dartClient {
provider = "dart run orm"
output = "../../../backend_dart/lib/infrastructure/persistence"
output = "../../../backend_dart/lib/infrastructure/persistence/db"
}
generator goClient {
provider = "go run github.com/steebchen/prisma-client-go"
output = "../../../backend-go/internal/infrastructure/persistence"
output = "../../../backend-go/internal/infrastructure/persistence/db"
}
datasource db {

6
backend-go/config.yaml Normal file
View File

@ -0,0 +1,6 @@
# config.yaml
database:
url: "postgres://user:secret@localhost:5432/time_tracking_db"
server:
port: "8080"

View File

@ -3,29 +3,25 @@ module actatempus_backend
go 1.23.2
require (
github.com/IBM/fp-go v1.0.150 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/joho/godotenv v1.5.1
github.com/shopspring/decimal v1.4.0
github.com/spf13/viper v1.19.0
github.com/steebchen/prisma-client-go v0.43.0
)
require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/steebchen/prisma-client-go v0.43.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect

View File

@ -1,21 +1,21 @@
github.com/IBM/fp-go v1.0.150 h1:pKTvZ/W9HOsUDVLbQr4bLlIG4fnf1G9V9h+Yc8N/K04=
github.com/IBM/fp-go v1.0.150/go.mod h1:spbj1nFoMpAGC/UnJM4XUYHNSQ+3JbD2u4LzwFBiwkw=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
@ -23,12 +23,16 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
@ -49,13 +53,10 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
@ -67,6 +68,8 @@ golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -1,41 +0,0 @@
package persistence
import (
"actatempus_backend/internal/domain/entities"
"actatempus_backend/internal/domain/repositories"
"database/sql"
)
type PostgresUserRepository struct {
db *sql.DB
}
func NewPostgresUserRepository(db *sql.DB) repositories.UserRepository {
return &PostgresUserRepository{db: db}
}
func (r *PostgresUserRepository) Create(user *entities.User) error {
_, err := r.db.Exec("INSERT INTO users (id, name, email, password) VALUES ($1, $2, $3, $4)",
user.ID, user.Name, user.Email, user.Password)
return err
}
func (r *PostgresUserRepository) FindByEmail(email string) (*entities.User, error) {
var user entities.User
err := r.db.QueryRow("SELECT id, name, email, password FROM users WHERE email = $1", email).
Scan(&user.ID, &user.Name, &user.Email, &user.Password)
if err != nil {
return nil, err
}
return &user, nil
}
func (r *PostgresUserRepository) FindByID(id string) (*entities.User, error) {
var user entities.User
err := r.db.QueryRow("SELECT id, name, email, password FROM users WHERE id = $1", id).
Scan(&user.ID, &user.Name, &user.Email, &user.Password)
if err != nil {
return nil, err
}
return &user, nil
}

6
backend_dart/config.yaml Normal file
View File

@ -0,0 +1,6 @@
# config.yaml
database:
url: "postgres://user:secret@localhost:5432/time_tracking_db"
server:
port: "8080"

View File

@ -2617,7 +2617,7 @@ class PrismaClient extends _i1.BasePrismaClient<PrismaClient> {
@override
get $engine => _engine ??= _i5.BinaryEngine(
schema:
'generator dartClient {\n provider = "dart run orm"\n output = "../../../backend_dart/lib/infrastructure/persistence"\n}\n\ngenerator goClient {\n provider = "go run github.com/steebchen/prisma-client-go"\n output = "../../../backend-go/internal/infrastructure/persistence"\n}\n\ndatasource db {\n provider = "postgresql"\n url = env("DATABASE_URL")\n}\n\n// User Model\nmodel User {\n id String @id @default(uuid())\n name String\n email String @unique\n password String\n projects Project[] // Beziehung zu Projekten\n timeEntries TimeEntry[] // Beziehung zu Zeiteinträgen\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n\n// Project Model\nmodel Project {\n id String @id @default(uuid())\n name String\n description String?\n clientId String?\n tasks Task[] // Beziehung zu Aufgaben\n timeEntries TimeEntry[] // Beziehung zu Zeiteinträgen\n user User @relation(fields: [userId], references: [id])\n userId String\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n\n// TimeEntry Model\nmodel TimeEntry {\n id String @id @default(uuid())\n startTime DateTime\n endTime DateTime\n description String?\n user User @relation(fields: [userId], references: [id])\n userId String\n project Project @relation(fields: [projectId], references: [id])\n projectId String\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n\n// Task Model (optional)\nmodel Task {\n id String @id @default(uuid())\n name String\n description String?\n project Project @relation(fields: [projectId], references: [id])\n projectId String\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n',
'generator dartClient {\n provider = "dart run orm"\n output = "../../../backend_dart/lib/infrastructure/persistence/db"\n}\n\ngenerator goClient {\n provider = "go run github.com/steebchen/prisma-client-go"\n output = "../../../backend-go/internal/infrastructure/persistence/db"\n}\n\ndatasource db {\n provider = "postgresql"\n url = env("DATABASE_URL")\n}\n\n// User Model\nmodel User {\n id String @id @default(uuid())\n name String\n email String @unique\n password String\n projects Project[] // Beziehung zu Projekten\n timeEntries TimeEntry[] // Beziehung zu Zeiteinträgen\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n\n// Project Model\nmodel Project {\n id String @id @default(uuid())\n name String\n description String?\n clientId String?\n tasks Task[] // Beziehung zu Aufgaben\n timeEntries TimeEntry[] // Beziehung zu Zeiteinträgen\n user User @relation(fields: [userId], references: [id])\n userId String\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n\n// TimeEntry Model\nmodel TimeEntry {\n id String @id @default(uuid())\n startTime DateTime\n endTime DateTime\n description String?\n user User @relation(fields: [userId], references: [id])\n userId String\n project Project @relation(fields: [projectId], references: [id])\n projectId String\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n\n// Task Model (optional)\nmodel Task {\n id String @id @default(uuid())\n name String\n description String?\n project Project @relation(fields: [projectId], references: [id])\n projectId String\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n',
datasources: const {
'db': _i1.Datasource(
_i1.DatasourceType.environment,

View File

@ -32,7 +32,7 @@ services:
# - REDIS_ARGS=--requirepass ${REDIS_PASSWORD:-password}
volumes:
- redis_data:/data
- ./docker/redis.conf:/usr/local/etc/redis/redis.conf
- ./_common/docker/redis.conf:/usr/local/etc/redis/redis.conf
#command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
volumes:

View File

@ -22,3 +22,9 @@
2. Dart: pnpx prisma generate
3. Push Schema to DB
1. go run github.com/steebchen/prisma-client-go db push
4. Run Backends
1. Adjust config in necessary
2. Inside the GoBackend folder run
go run cmd/actatempus/main.go
3. Inside the DartBackend folder run
dart run .\bin\backend_dart.dart