adding in file path option

This commit is contained in:
2025-09-07 01:29:18 -04:00
parent 006af98328
commit a2cb04fd09
2 changed files with 29 additions and 3 deletions
+8 -1
View File
@@ -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
}