summaryrefslogtreecommitdiff
path: root/api/database/database.go
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-08 14:37:33 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-08 14:39:13 +0200
commit1f0d9ec8452f15c27cd33c4e3874454c35993743 (patch)
treec453a31ae5eb823aaf48868eea9fc4daf65f108b /api/database/database.go
parentc5b10e28b358308d8349b940af09f64368172f2e (diff)
Use internal/pkg structure
Diffstat (limited to 'api/database/database.go')
-rw-r--r--api/database/database.go32
1 files changed, 0 insertions, 32 deletions
diff --git a/api/database/database.go b/api/database/database.go
deleted file mode 100644
index 4470c58..0000000
--- a/api/database/database.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package database
-
-import (
- "gorm.io/driver/postgres"
- "gorm.io/gorm"
-
- "errors"
-)
-
-// Global variable but private
-var db *gorm.DB = nil
-
-// Init the database from a DSN string which must be a valid PostgreSQL dsn.
-// Also, auto migrate all the models.
-func InitDb(dsn string) (*gorm.DB, error) {
- var err error
- db, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
-
- if err == nil {
- db.AutoMigrate(&User{}, &Game{})
- }
-
- return db, err
-}
-
-// Return the instance or error if the config is not laoded yet
-func GetDb() (*gorm.DB, error) {
- if db == nil {
- return nil, errors.New("You must call `InitDb()` first.")
- }
- return db, nil
-}