1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00
miniflux-v2/storage/storage.go

37 lines
858 B
Go
Raw Normal View History

2017-11-19 21:10:04 -08: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.
2018-08-24 21:51:50 -07:00
package storage // import "miniflux.app/storage"
2017-11-19 21:10:04 -08:00
import (
"database/sql"
)
2017-11-27 21:30:04 -08:00
// Storage handles all operations related to the database.
2017-11-19 21:10:04 -08:00
type Storage struct {
db *sql.DB
}
2017-11-27 21:30:04 -08:00
// NewStorage returns a new Storage.
2018-08-01 20:28:45 -07:00
func NewStorage(db *sql.DB) *Storage {
return &Storage{db}
2017-11-19 21:10:04 -08:00
}
// DatabaseVersion returns the version of the database which is in use.
func (s *Storage) DatabaseVersion() string {
var dbVersion string
err := s.db.QueryRow(`SELECT current_setting('server_version')`).Scan(&dbVersion)
if err != nil {
return err.Error()
}
return dbVersion
}
// Ping checks if the database connection works.
func (s *Storage) Ping() error {
_, err := s.db.Exec(`SELECT true`)
return err
}