1
0
Fork 0
miniflux/storage/storage.go

37 lines
812 B
Go
Raw Normal View History

2017-11-20 00:10:04 -05:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package storage
import (
"database/sql"
2017-11-28 00:30:04 -05:00
// Postgresql driver import
2017-11-20 00:10:04 -05:00
_ "github.com/lib/pq"
2017-12-15 21:55:57 -05:00
"github.com/miniflux/miniflux/logger"
2017-11-20 00:10:04 -05:00
)
2017-11-28 00:30:04 -05:00
// Storage handles all operations related to the database.
2017-11-20 00:10:04 -05:00
type Storage struct {
db *sql.DB
}
2017-11-28 00:30:04 -05:00
// Close closes all database connections.
2017-11-20 00:10:04 -05:00
func (s *Storage) Close() {
s.db.Close()
}
2017-11-28 00:30:04 -05:00
// NewStorage returns a new Storage.
func NewStorage(databaseURL string, maxOpenConns int) *Storage {
db, err := sql.Open("postgres", databaseURL)
2017-11-20 00:10:04 -05:00
if err != nil {
2017-12-15 21:55:57 -05:00
logger.Fatal("[Storage] Unable to connect to the database: %v", err)
2017-11-20 00:10:04 -05:00
}
db.SetMaxOpenConns(maxOpenConns)
db.SetMaxIdleConns(2)
return &Storage{db: db}
}