sqlx-ts icon indicating copy to clipboard operation
sqlx-ts copied to clipboard

With loading dot env in sqx-ts

Open Leo5878 opened this issue 8 months ago • 2 comments

Hi! If i understand correctly, i just need to create a .env file for sqx-ts to load environment variables and run the script. However, something is not working as expected.

Could you clarify if there are any additional steps required or if i might be missing something?

yarn sqlx-ts ./src

[WARN] Failed to read config file from the path: ".sqlxrc.json"
[ERROR] Unable to retrieve a database type, please check your configuration and try again

thread 'main' panicked at src/common/config.rs:219:9:

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error Command failed with exit code 101.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Example of my .env

DB_HOST=127.0.0.1
DB_NAME=backend
DB_PASS=
DB_USER=
DB_PORT=5432
DB_TYPE=postgres

Leo5878 avatar Mar 26 '25 00:03 Leo5878

hey, the error says it cannot read .sqlxrc.json file, are you sure .sqlxrc.json is present?

JasonShin avatar Mar 27 '25 00:03 JasonShin

Yes, .sqlxrc.json exists. But if I don’t specify -c .sqlxrc.json, it doesn’t find it. If I do specify it, it complains about missing fields in .sqlxrc. The missing fields are exported as environment variables, and I can see them using the env command.

{
  "generateTypes": {
    "enabled": true,
    "convertToCamelCaseColumnName": true
  },
}

Leo5878 avatar Mar 30 '25 11:03 Leo5878

I believe this issue is now resolved in v0.22.0, thanks for your contribution!

JasonShin avatar Jun 14 '25 13:06 JasonShin