From 88e1b886e5471552c055374f71d848d3a3dcb4b6 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 5 Mar 2026 12:21:04 +0100 Subject: feat(db): connect with sql instead of gorm --- common/config.go | 12 ++++-------- common/context.go | 9 ++++----- 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'common') 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 { -- cgit v1.2.3