mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* Bump golangci-lint version, update Go version deps and generic code improvements * Fix wesbocket resp nil check and zip closures * Update pprof path
30 lines
671 B
Go
30 lines
671 B
Go
package sqlite
|
|
|
|
import (
|
|
"database/sql"
|
|
"path/filepath"
|
|
|
|
// import sqlite3 driver
|
|
_ "github.com/mattn/go-sqlite3"
|
|
"github.com/thrasher-corp/gocryptotrader/database"
|
|
)
|
|
|
|
// Connect opens a connection to sqlite database and returns a pointer to database.DB
|
|
func Connect() (*database.Instance, error) {
|
|
if database.DB.Config.Database == "" {
|
|
return nil, database.ErrNoDatabaseProvided
|
|
}
|
|
|
|
databaseFullLocation := filepath.Join(database.DB.DataPath, database.DB.Config.Database)
|
|
|
|
dbConn, err := sql.Open("sqlite3", databaseFullLocation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
database.DB.SQL = dbConn
|
|
database.DB.SQL.SetMaxOpenConns(1)
|
|
|
|
return database.DB, nil
|
|
}
|