func Open(dbPath string, fkEnabled bool) (*DB, error) {
	rwDSN := fmt.Sprintf("file:%s?_fk=%s", dbPath, strconv.FormatBool(fkEnabled))
	rwDB, err := sql.Open("sqlite3", rwDSN)
	if err != nil {
		return nil, err
	}
	roOpts := []string{
		"mode=ro",
		fmt.Sprintf("_fk=%s", strconv.FormatBool(fkEnabled)),
	}
	roDSN := fmt.Sprintf("file:%s?%s", dbPath, strings.Join(roOpts, "&"))
	roDB, err := sql.Open("sqlite3", roDSN)
	if err != nil {
		return nil, err
	}
	if err := rwDB.Ping(); err != nil {
		return nil, fmt.Errorf("failed to ping on-disk database: %s", err.Error())
	}
	rwDB.SetConnMaxIdleTime(30 * time.Second)
	rwDB.SetConnMaxLifetime(0)
	roDB.SetConnMaxIdleTime(30 * time.Second)
	roDB.SetConnMaxLifetime(0)
	return &DB{
		path:  dbPath,
		rwDB:  rwDB,
		roDB:  roDB,
		rwDSN: rwDSN,
		roDSN: roDSN,
	}, nil
}
Open opens a file-based database, creating it if it does not exist.
package db
import (
	"context"
	"database/sql"
	"expvar"
	"fmt"
	"io"
	"math/rand"
	"os"
	"strconv"
	"strings"
	"time"
	"github.com/rqlite/go-sqlite3"
	"github.com/rqlite/rqlite/command"
)
const bkDelay = 250
const (
	onDiskMaxOpenConns = 32
	onDiskMaxIdleTime  = 120 * time.Second
	numExecutions      = "executions"
	numExecutionErrors = "execution_errors"
	numQueries         = "queries"
	numQueryErrors     = "query_errors"
	numETx             = "execute_transactions"
	numQTx             = "query_transactions"
)
var DBVersion string
var stats *expvar.Map
func init() {
	DBVersion, _, _ = sqlite3.Version()
	stats = expvar.NewMap("db")
	stats.Add(numExecutions, 0)
	stats.Add(numExecutionErrors, 0)
	stats.Add(numQueries, 0)
	stats.Add(numQueryErrors, 0)
	stats.Add(numETx, 0)
	stats.Add(numQTx, 0)
}
type DB struct {
	path   string  
	memory bool    
	rwDB *sql.DB  
	roDB *sql.DB  
	rwDSN string  
	roDSN string  
}
type PoolStats struct {
	MaxOpenConnections int           `json:"max_open_connections"`
	OpenConnections    int           `json:"open_connections"`
	InUse              int           `json:"in_use"`
	Idle               int           `json:"idle"`
	WaitCount          int64         `json:"wait_count"`
	WaitDuration       time.Duration `json:"wait_duration"`
	MaxIdleClosed      int64         `json:"max_idle_closed"`
	MaxIdleTimeClosed  int64         `json:"max_idle_time_closed"`
	MaxLifetimeClosed  int64         `json:"max_lifetime_closed"`
}