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

Improve health check endpoint to test database connection

This commit is contained in:
Frédéric Guillot 2021-02-19 18:47:50 -08:00 committed by fguillot
parent c2571f9f47
commit e3c28a6c96
4 changed files with 29 additions and 14 deletions

View file

@ -17,3 +17,20 @@ type Storage struct {
func NewStorage(db *sql.DB) *Storage {
return &Storage{db}
}
// 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
}