Skip to content

fix(sqlite3): support relative path for dbname#1471

Open
KeitaShimura wants to merge 1 commit intoaarondl:masterfrom
KeitaShimura:fix/sqlite3-relative-path
Open

fix(sqlite3): support relative path for dbname#1471
KeitaShimura wants to merge 1 commit intoaarondl:masterfrom
KeitaShimura:fix/sqlite3-relative-path

Conversation

@KeitaShimura
Copy link
Contributor

Summary

  • Users can now specify a relative path (e.g. ./mydb.sqlite) for dbname in sqlboiler.toml
  • In Assemble, the dbname is resolved to an absolute path via filepath.Abs() before building the connection string

Problem

When a relative path was given as dbname, SQLite resolved it against the working directory at the time of execution. Since the working directory when running sqlboiler differs from the one used when running generated tests, the same relative path pointed to different locations, causing no such table errors.

Changes

drivers/sqlboiler-sqlite3/driver/sqlite3.go

  • Resolve dbname to an absolute path with filepath.Abs() if it is not already absolute

drivers/sqlboiler-sqlite3/driver/sqlite3_test.go

  • Extract DB creation logic into a createSQLiteDB helper
  • Add test cases for each path format:
Test case Path format Example filepath.IsAbs() Resolved by filepath.Abs()
absolute_path Absolute path /var/folders/.../mydb.sql true (no-op) -
relative_path Relative path with ../ ../../var/folders/.../mydb.sql false yes
relative_path_dot_slash Relative path with ./ ./mydb.sql false yes

Related issue

Related to #1409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant