diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-05 12:21:04 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-07 13:31:35 +0100 |
| commit | 88e1b886e5471552c055374f71d848d3a3dcb4b6 (patch) | |
| tree | d3e64db1fa350339ac147c04d02ab7baea82e6d9 /common | |
| parent | 89b23632f5ceeebd82132210c1407dc9514a547b (diff) | |
feat(db): connect with sql instead of gorm
Diffstat (limited to 'common')
| -rw-r--r-- | common/config.go | 12 | ||||
| -rw-r--r-- | common/context.go | 9 |
2 files changed, 8 insertions, 13 deletions
diff --git a/common/config.go b/common/config.go index 8cb74ab..5519690 100644 --- a/common/config.go +++ b/common/config.go @@ -1,12 +1,12 @@ package common import ( + "database/sql" "fmt" "os" + _ "github.com/lib/pq" "github.com/pelletier/go-toml/v2" - "gorm.io/driver/postgres" - "gorm.io/gorm" ) type Config struct { @@ -31,12 +31,8 @@ func (p *PostgresConfig) SetDefaultValues() { p.Port = 5432 } -func (p *PostgresConfig) Connect() (*gorm.DB, error) { - db, err := gorm.Open(postgres.Open(p.generateDsn()), &gorm.Config{}) - if err != nil { - return nil, err - } - return db, nil +func (p *PostgresConfig) Connect() (*sql.DB, error) { + return sql.Open("postgres", p.generateDsn()) } // generateDsn for the connection to postgres using the given config.SQLCredentials diff --git a/common/context.go b/common/context.go index 740e727..8bb02b2 100644 --- a/common/context.go +++ b/common/context.go @@ -2,8 +2,7 @@ package common import ( "context" - - "gorm.io/gorm" + "database/sql" ) type Key uint8 @@ -15,16 +14,16 @@ const ( KeyCopaingState Key = 3 ) -func SetDB(ctx context.Context, db *gorm.DB) context.Context { +func SetDB(ctx context.Context, db *sql.DB) context.Context { return context.WithValue(ctx, keyDB, db) } -func GetDB(ctx context.Context) *gorm.DB { +func GetDB(ctx context.Context) *sql.DB { raw := ctx.Value(keyDB) if raw == nil { return nil } - return raw.(*gorm.DB).WithContext(ctx) + return raw.(*sql.DB) } func SetDebug(ctx context.Context, b bool) context.Context { |
