diff options
| author | Bobby <[email protected]> | 2026-03-06 23:01:58 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-06 23:01:58 +0530 |
| commit | ed2a033d7c08e448f5c6fd035e2de8f51431b597 (patch) | |
| tree | abe46463fc761b2e4266aadedb6b88c5493ce29b /database/database.go | |
| parent | 3f07a4b6c745707f135a7a97e93b0fa770b67873 (diff) | |
| download | dove-ed2a033d7c08e448f5c6fd035e2de8f51431b597.tar.xz dove-ed2a033d7c08e448f5c6fd035e2de8f51431b597.zip | |
Implement database connection and routing system with HTTP method support
Diffstat (limited to 'database/database.go')
| -rw-r--r-- | database/database.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/database/database.go b/database/database.go new file mode 100644 index 0000000..27b99eb --- /dev/null +++ b/database/database.go @@ -0,0 +1,36 @@ +package database + +import ( + "dove/messages" + "dove/utils/logger" + + "gorm.io/driver/sqlite" + "gorm.io/gorm" +) + +var DB *gorm.DB + +func init() { + databaseDSN := resolveDatabasePath() + dialector := sqlite.Open(databaseDSN) + + var connectionError error + DB, connectionError = gorm.Open(dialector, &gorm.Config{ + Logger: resolveGORMLogLevel(), + }) + + if connectionError != nil { + logger.Fatalf(LOG_PREFIX, messages.DatabaseConnectionFailed, connectionError) + } + + sqlDB, poolError := DB.DB() + if poolError != nil { + logger.Fatalf(LOG_PREFIX, messages.DatabasePoolConfigFailed, poolError) + } + + sqlDB.SetMaxOpenConns(MAX_OPEN_CONNECTIONS) + sqlDB.SetMaxIdleConns(MAX_IDLE_CONNECTIONS) + sqlDB.SetConnMaxLifetime(MAX_CONNECTION_LIFETIME) + + logger.Successf(LOG_PREFIX, messages.DatabaseConnected, databaseDSN) +} |
