adding in file path option
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/ncruces/go-sqlite3/driver"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
|
||||
type database struct {
|
||||
file string
|
||||
path string
|
||||
sqlite *sqlx.DB
|
||||
}
|
||||
|
||||
@@ -34,7 +36,12 @@ func New(opts ...Option) (Database, error) {
|
||||
opt(db)
|
||||
}
|
||||
|
||||
slite, err := sqlx.Open("sqlite3", fmt.Sprintf("file:%s", db.file))
|
||||
filePath := db.file
|
||||
if db.path != "" {
|
||||
filePath = path.Join(db.path, db.file)
|
||||
}
|
||||
|
||||
slite, err := sqlx.Open("sqlite3", fmt.Sprintf("file:%s", filePath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user