Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion drivers/sqlboiler-sqlite3/driver/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/base64"
"fmt"
"io/fs"
"path/filepath"
"strings"

_ "modernc.org/sqlite"
Expand Down Expand Up @@ -74,6 +75,13 @@ func (s SQLiteDriver) Assemble(config drivers.Config) (dbinfo *drivers.DBInfo, e
blacklist, _ := config.StringSlice(drivers.ConfigBlacklist)
concurrency := config.DefaultInt(drivers.ConfigConcurrency, drivers.DefaultConcurrency)

if !filepath.IsAbs(dbname) {
dbname, err = filepath.Abs(dbname)
if err != nil {
return nil, fmt.Errorf("sqlboiler-sqlite failed to resolve database path: %w", err)
}
}

s.connStr = SQLiteBuildQueryString(dbname)
s.configForeignKeys = config.MustForeignKeys(drivers.ConfigForeignKeys)
s.dbConn, err = sql.Open("sqlite", s.connStr)
Expand Down Expand Up @@ -685,4 +693,4 @@ func (SQLiteDriver) Imports() (col importers.Collection, err error) {
},
}
return col, err
}
}
53 changes: 41 additions & 12 deletions drivers/sqlboiler-sqlite3/driver/sqlite3_test.go

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the tests needed to be modified.

@KeitaShimura KeitaShimura May 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenafamo
I have no plans to make any further fixes. Given the time that has passed, please go ahead and close the PR if it’s no longer needed.

Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,28 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/aarondl/sqlboiler/v4/drivers"
"github.com/stretchr/testify/require"
_ "modernc.org/sqlite"
)

var (
flagOverwriteGolden = flag.Bool("overwrite-golden", false, "Overwrite the golden file with the current execution results")
)

func createSQLiteDB(t *testing.T, path string, sql []byte) {
t.Helper()
out := &bytes.Buffer{}
cmd := exec.Command("sqlite3", path)
cmd.Stdout = out
cmd.Stderr = out
cmd.Stdin = bytes.NewReader(sql)
if err := cmd.Run(); err != nil {
t.Logf("sqlite output:\n%s\n", out.Bytes())
t.Fatal(err)
}
}

func TestDriver(t *testing.T) {
rand.New(rand.NewSource(time.Now().Unix()))
b, err := os.ReadFile("testdatabase.sql")
Expand All @@ -29,32 +42,48 @@ func TestDriver(t *testing.T) {
}

tmpName := filepath.Join(os.TempDir(), fmt.Sprintf("sqlboiler-sqlite3-%d.sql", rand.Int()))

out := &bytes.Buffer{}
createDB := exec.Command("sqlite3", tmpName)
createDB.Stdout = out
createDB.Stderr = out
createDB.Stdin = bytes.NewReader(b)

createSQLiteDB(t, tmpName, b)
t.Log("sqlite file:", tmpName)
if err := createDB.Run(); err != nil {
t.Logf("sqlite output:\n%s\n", out.Bytes())

cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
t.Logf("sqlite output:\n%s\n", out.Bytes())
relName, err := filepath.Rel(cwd, tmpName)
if err != nil {
t.Fatal(err)
}

localName := fmt.Sprintf("./sqlboiler-sqlite3-local-%d.sql", rand.Int())
createSQLiteDB(t, localName, b)
t.Cleanup(func() { os.Remove(localName) })

tests := []struct {
name string
config drivers.Config
goldenJson string
}{
{
name: "default",
name: "absolute_path",
config: drivers.Config{
"dbname": tmpName,
},
goldenJson: "sqlite3.golden.json",
},
{
name: "relative_path",
config: drivers.Config{
"dbname": relName,
},
goldenJson: "sqlite3.golden.json",
},
{
name: "relative_path_dot_slash",
config: drivers.Config{
"dbname": localName,
},
goldenJson: "sqlite3.golden.json",
},
}

for _, tt := range tests {
Expand Down