Configuration

Example 1: Single database connection using CLI options

Run this in your terminal

sqlx-ts ./src/app \
    --db-host=127.0.0.1 \ 
    --db-port=54321 \
    --db-type=postgres \
    --db-user=postgres \
    --db-pass=postgres \
    --generate-types

The CLI can be triggered in this format sqlx-ts check the CLI Options page for more details.

Example 2: single database connection using .sqlxrc.json file

Create a file called .sqlxrc.json at the root level of your project where you will run sqlx-ts binary

{
  "generateTypes": {
    "enabled": true
  },
  "connections": {
    "default": {
      "DB_TYPE": "postgres",
      "DB_HOST": "127.0.0.1",
      "DB_PORT": 54321,
      "DB_USER": "postgres",
      "DB_PASS": "postgres",
      "DB_NAME": "postgres"
    }
  }
}

Then run this in your terminal

cargo run ./src/app --config .sqlxrc.json

Example 3: Multiple database connections using .sqlxrc.json file

Create a file called .sqlxrc.json at the root level of your project where you will run sqlx-ts binary

{
  "generateTypes": {
    "enabled": true
  },
  "connections": {
    "default": {
      "DB_TYPE": "postgres",
      "DB_HOST": "127.0.0.1",
      "DB_PORT": 4321,
      "DB_USER": "postgres",
      "DB_PASS": "postgres",
      "DB_NAME": "postgres"
    },
    "mysql": {
      "DB_TYPE": "mysql",
      "DB_HOST": "127.0.0.1",
      "DB_PORT": 3306,
      "DB_USER": "root",
      "DB_NAME": "mysql"
    }
  }
}

Then run this in your terminal

cargo run ./src/app --config .sqlxrc.json

Notes

By default, sql check operation ignores node_modules. Any extra ignore paths can be specified using --ignore=<path>.