Skip to main content

Environment variables

Environment variablesDescription
DB_URLPrimary database connection URL (e.g. postgres://user:pass@host:port/dbname or mysql://user:pass@host:port/dbname). If provided, this overrides individual connection parameters
DB_HOSTPrimary DB host
DB_PASSPrimary DB password
DB_PORTPrimary DB port number
DB_TYPEType of primary database to connect [default: postgres] [possible values: postgres, mysql]
DB_USERPrimary DB user name
DB_NAMEPrimary DB name
PG_SEARCH_PATHPostgreSQL schema search path (default is "$user,public") https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH

Examples

Using individual connection parameters

export DB_TYPE=postgres
export DB_HOST=127.0.0.1
export DB_PORT=5432
export DB_USER=postgres
export DB_PASS=postgres
export DB_NAME=mydb

sqlx-ts <path>

Using database URL

Alternatively, you can use DB_URL to specify the complete connection string:

# PostgreSQL
export DB_TYPE=postgres
export DB_URL=postgres://postgres:postgres@localhost:5432/mydb

sqlx-ts <path>

# MySQL
export DB_TYPE=mysql
export DB_URL=mysql://root:password@localhost:3306/mydatabase

sqlx-ts <path>

Note: When DB_URL is set, it takes precedence over individual connection parameters (DB_HOST, DB_PORT, DB_USER, DB_PASS, DB_NAME).