1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Create database package (refactoring)

This commit is contained in:
Frédéric Guillot 2018-08-01 20:28:45 -07:00
parent 17054b396e
commit cf03e0e338
30 changed files with 61 additions and 54 deletions

View file

@ -6,10 +6,6 @@ package storage
import (
"database/sql"
// Postgresql driver import
_ "github.com/lib/pq"
"github.com/miniflux/miniflux/logger"
)
// Storage handles all operations related to the database.
@ -17,20 +13,7 @@ type Storage struct {
db *sql.DB
}
// Close closes all database connections.
func (s *Storage) Close() {
s.db.Close()
}
// NewStorage returns a new Storage.
func NewStorage(databaseURL string, maxOpenConns int) *Storage {
db, err := sql.Open("postgres", databaseURL)
if err != nil {
logger.Fatal("[Storage] Unable to connect to the database: %v", err)
}
db.SetMaxOpenConns(maxOpenConns)
db.SetMaxIdleConns(2)
return &Storage{db: db}
func NewStorage(db *sql.DB) *Storage {
return &Storage{db}
}