storage.go 858 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package storage // import "miniflux.app/storage"
  5. import (
  6. "database/sql"
  7. )
  8. // Storage handles all operations related to the database.
  9. type Storage struct {
  10. db *sql.DB
  11. }
  12. // NewStorage returns a new Storage.
  13. func NewStorage(db *sql.DB) *Storage {
  14. return &Storage{db}
  15. }
  16. // DatabaseVersion returns the version of the database which is in use.
  17. func (s *Storage) DatabaseVersion() string {
  18. var dbVersion string
  19. err := s.db.QueryRow(`SELECT current_setting('server_version')`).Scan(&dbVersion)
  20. if err != nil {
  21. return err.Error()
  22. }
  23. return dbVersion
  24. }
  25. // Ping checks if the database connection works.
  26. func (s *Storage) Ping() error {
  27. _, err := s.db.Exec(`SELECT true`)
  28. return err
  29. }