func (sql Storage) Fetch(name string) ([]types.Result, error) {
	db, err := sql.dbConnect()
	if err != nil {
		return nil, err
	}
	defer db.Close()
	var checkResult []byte
	var results []types.Result
	err = db.Get(&checkResult, `SELECT results FROM "checks" WHERE name=$1 LIMIT 1`, name)
	if err != nil {
		return nil, err
	}
	if err = json.Unmarshal(checkResult, &results); err != nil {
		return nil, err
	}
	return results, nil
}
Fetch fetches results of the check with given name.
package sql
import (
	"encoding/json"
	"errors"
	"fmt"
	"strconv"
	"time"
	"github.com/jmoiron/sqlx"
	_ "github.com/lib/pq"            
	_ "github.com/mattn/go-sqlite3"  
	"github.com/sourcegraph/checkup/storage/fs"
	"github.com/sourcegraph/checkup/types"
)
const schema = `
CREATE TABLE checks (
    name TEXT NOT NULL PRIMARY KEY,
    timestamp INT8 NOT NULL,
    results TEXT
);
CREATE UNIQUE INDEX idx_checks_timestamp ON checks(timestamp);
`
type Storage struct {
	SqliteDBFile string `json:"sqlite_db_file,omitempty"`
	PostgreSQL *struct {
		Host     string `json:"host,omitempty"`
		Port     int    `json:"port,omitempty"`
		User     string `json:"user"`
		Password string `json:"password,omitempty"`
		DBName   string `json:"dbname"`
		SSLMode  string `json:"sslmode,omitempty"`
	} `json:"postgresql"`
	CheckExpiry time.Duration `json:"check_expiry,omitempty"`
}
func New(config json.RawMessage) (Storage, error) {
	var storage Storage
	err := json.Unmarshal(config, &storage)
	return storage, err
}
func (Storage) Type() string {
	return Type
}
func (sql Storage) dbConnect() (*sqlx.DB, error) {
	if sql.SqliteDBFile != "" && sql.PostgreSQL != nil {
		return nil, errors.New("several SQL backends are configured")
	}
	fmt.Println("The 'sql' backend is deprecated and will be removed in the future.")
	fmt.Println("Please switch to a database-specific storage configuration.")
	if sql.SqliteDBFile != "" {
		return sqlx.Connect("sqlite3", sql.SqliteDBFile)
	}
	if sql.PostgreSQL != nil {
		var pgOptions string
		if sql.PostgreSQL.DBName == "" {
			return nil, errors.New("missing PostgreSQL database name")
		}
		if sql.PostgreSQL.User == "" {
			return nil, errors.New("missing PostgreSQL username")
		}
		if sql.PostgreSQL.Host != "" {
			pgOptions += " host=" + sql.PostgreSQL.Host
		}
		if sql.PostgreSQL.Port != 0 {
			pgOptions += " port=" + strconv.Itoa(sql.PostgreSQL.Port)
		}
		pgOptions += " user=" + sql.PostgreSQL.User
		if sql.PostgreSQL.Password != "" {
			pgOptions += " password=" + sql.PostgreSQL.Password
		}
		pgOptions += " dbname=" + sql.PostgreSQL.DBName
		if sql.PostgreSQL.SSLMode != "" {
			pgOptions += " sslmode=" + sql.PostgreSQL.SSLMode
		}
		return sqlx.Connect("postgres", pgOptions)
	}
	return nil, errors.New("no configured database backend")
}
func (sql Storage) GetIndex() (map[string]int64, error) {
	db, err := sql.dbConnect()
	if err != nil {
		return nil, err
	}
	defer db.Close()
	idx := make(map[string]int64)
	var check struct {
		Name      string `db:"name"`
		Timestamp int64  `db:"timestamp"`
	}
	rows, err := db.Queryx(`SELECT name,timestamp FROM "checks"`)
	if err != nil {
		return nil, err
	}
	for rows.Next() {
		err := rows.StructScan(&check)
		if err != nil {
			rows.Close()
			return nil, err
		}
		idx[check.Name] = check.Timestamp
	}
	return idx, nil
}