DBT jinja/sql formatter
npm install dbt-formatter
``bash`
npm install -s dbt-formatter
`javascript
import formatter from 'dbt-formatter';
const mySql = "SELECT * FROM {{ ref('myTableRef') }}";
const myOpts = { sql: 'default', indent: 2, upper: false };
formatter.format(mySql, myOpts);
`
This will result in:
`sql`
SELECT
*
FROM
{{ ref('myTableRef') }}
Fine tune dbt-formatter behavior with the following options:
| Option | Default | Description |
| -------------- | --------- | ---------------------------------------------------------------------- |
| sql | default | The sql dialect you want to use, currently only default is available |2
| indent | | How many spaces you want an indentation to be |false
| upper | | Formats sql reserved words to be uppercase when set to true |false
| newline | | Appends a new line at the end of the formatted sql string |false
| lowerWords | | Lowercases all words as identified by the tokenizer |true
| allowCamelcase | | Allows column names to be camelcased |
- npm test: Run test suitenpm start
- : Run npm run build in watch modenpm run build
- : Generate bundles and typings, create docsnpm run lint
- : Lints codenpm run package`: Package dbt-formatter as a binary
-
- Add more sql dialects:
- [x] snowflake
- [ ] redshift
- [ ] bigquery
- [ ] postgres
- [ ] presto