sqlboiler
sqlboiler copied to clipboard
Make sqlite3 db path relative to sqlboiler config file
Having a Go project with a file structure like the following is problematic when using absolute or relative paths as suggested for the sqlite3 database in the sqlboiler config.
| project/
| -- cmd/
| ---- main.go
| -- db/
| ---- sqlite.db
| -- sqlboiler.toml
| -- go.mod
sqlboiler.toml
[sqlite3]
dbname = "db/sqlite.db"
The generation command works fine if ran in root ✅
sqlboiler --config ./sqlboiler.toml --output ./models sqlite3
The path-adjusted Go generate command in main.go
will fail ❌
//go:generate sqlboiler --config ../sqlboiler.toml --output ../models sqlite3
The sqlite3 driver is not capable of finding the database sqlite.db
as relative paths don't match. The problem can be solved by (optionally) resolving the sqlite3 database' path relative to the sqlboiler config, not the execution context.