Command Line Interface References
The SQLX-TS
Command Line Interface (CLI) lets you execute linting from the terminal. The CLI has a variety of options that you can pass to configure sqlx-ts.
Run the CLI
SQLX-TS requires Node.js for installation. Follow the instructions in the Getting Started Guide to install sqlx-ts.
Most users use npx to run SQLX-TS on the command line like this:
- npm
- yarn
npx sqlx-ts [options] <PATH>
yarn sqlx-ts [options] <PATH>
such as:
- npm
- yarn
# run SQLX-TS to validates SQLs and generate types
npx sqlx-ts \
--db-type=postgres \
--db-host=127.0.01 \
--db-port=54321 \
--db-user=postgres \
--db-pass=postgres \
./src/app -g
# run SQLX-TS to validates SQLs and generate types
yarn dlx sqlx-ts \
--db-type=postgres \
--db-host=127.0.01 \
--db-port=54321 \
--db-user=postgres \
--db-pass=postgres \
./src/app -g
or
- npm
- yarn
# run sqlx-ts to validates SQLs and generate types
npx sqlx-ts --config=.sqlxrc.json ./src/app
# run SQLX-TS to validates SQLs and generate types
yarn dlx sqlx-ts --config=.sqlxrc.json ./src/app
Options
You can view all the CLI options by running npx sqlx-ts --help
A tool for Javascript/Typescript for compile-time safe SQL queries
USAGE:
sqlx-ts [OPTIONS] <PATH>
ARGS:
<PATH> Path to the Typescript or Javascript project
OPTIONS:
--config <CONFIG>
Path to the file based configuration
--db-host <DB_HOST>
Primary DB host
--db-name <DB_NAME>
Primary DB database name
--db-pass <DB_PASS>
Primary DB pass
--db-port <DB_PORT>
Primary DB Port
--db-type <DB_TYPE>
Type of primary database to connect [possible values: postgres, mysql]
--db-user <DB_USER>
Primary DB user
--ext <EXT>
Javascript Extension [default: ts] [possible values: ts, js]
-g, --generate-types
generate types of raw SQLs using default configuration
--generate-path <GENERATE_PATH>
generates types in a target directory path or a file
-h, --help
Print help information
--ignore <IGNORE>...
Folder paths to ignore
--log-level <LOG_LEVEL>
log level to be used for the CLI debug > info > warn > error [possible values: debug,
info, warning, error]
-m, --message-format <MESSAGE_FORMAT>
--pg-search-path <PG_SEARCH_PATH>
PostgreSQL schema search path (default is "$user,public")
https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH
-V, --version
Print version information
Basic Configuration
--config
This option allows you to specify an additional configuration file for SQLX-TS. (See Configuration File for more)
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json ./src/app
yarn dlx sqlx-ts --config=.sqlxrc.json ./src/app
--db-host
URL to the database that SQLX-TS should point to
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json --db-host=127.0.0.1 ./src/app
yarn dlx sqlx-ts --config=.sqlxrc.json --db-host=127.0.0.1 ./src/app
--db-name
Name of the database that you connect to
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json --db-name=sqlx ./src/app
yarn dlx sqlx-ts --config=.sqlxrc.json --db-name=sqlx ./src/app
--db-port
Port number of the database that you connect to
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json --db-port=3306 ./src/app
yarn dlx sqlx-ts --config=.sqlxrc.json --db-port=3306 ./src/app
--db-type
Type of the database that you connect to. It can be either mysql
or postgres
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json --db-type=postgres ./src/app
yarn dlx sqlx-ts --config=.sqlxrc.json --db-type=postgres ./src/app
--db-user
user of the database that you connect to
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json --db-user=postgres ./src/app
yarn dlx sqlx-ts --config=.sqlxrc.json --db-user=postgres ./src/app
--ext
File extensions to search. It can be either ts
| js
- [default: ts]
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json --ext=ts ./src/app
yarn dlx sqlx-ts --config=.sqlxrc.json --ext=ts ./src/app
-g, --generate-types
generate type definitions of SQLs detected by SQLX-TS
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json ./src/app -g
yarn dlx sqlx-ts --config=.sqlxrc.json ./src/app -g
--generate-path
File path to generate types
- npm
- yarn
npx sqlx-ts --config=.sqlxrc.json --generate-path=src/app/queries.ts ./src/app
yarn dlx sqlx-ts --config=.sqlxrc.json --generate-path=src/app/queries.ts ./src/app
-h, --help
Shows all SQLX-TS CLI options
- npm
- yarn
npx sqlx-ts --help
yarn dlx sqlx-ts --help
--ignore
File/Folder path patterns to ignore. The additional ignore patterns provided by this flag will
be added to the base ignore patters (*.queries.ts
and *.queries.js
also the patterns provided by .sqlxrcignore file)
- npm
- yarn
npx sqlx-ts --ignore=src/app/select.ts --ignore=src/app/stuff --ignore src/app/select.*.ts
yarn dlx sqlx-ts --ignore=src/app/select.ts --ignore=src/app/stuff --ignore src/app/select.*.ts
--log-level
log level to be used for the CLI - level follows in this order: debug > info > warning > error
[possible values: debug, info, warning, error].
(default is info
)
- npm
- yarn
npx sqlx-ts --ignore=src/app/select.ts --log-level=error
yarn dlx sqlx-ts --ignore=src/app/select.ts --log-level=error
--pg-search-path
PostgreSQL schema search path (default is "$user,public") https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH
- npm
- yarn
npx sqlx-ts --ignore=src/app/select.ts --pg-search-path=public,myschema
yarn dlx sqlx-ts --ignore=src/app/select.ts --pg-search-path=public,myschema
-V, --version
Prints version information of sqlx-ts CLI
- npm
- yarn
npx sqlx-ts --version
yarn dlx sqlx-ts --version