Skip to content

Commit f907e99

Browse files
committed
Add FAQ entry about SQL templating
1 parent 5085e78 commit f907e99

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,27 @@ extension is no more maintained by its author.
221221
Please use the official [SQL Formatter VSCode](https://marketplace.visualstudio.com/items?itemName=ReneSaarsoo.sql-formatter-vsc)
222222
extension to get the latest fixes from SQL Formatter library.
223223

224+
### My SQL contains templating syntax which SQL Formatter fails to parse
225+
226+
For example, you might have an SQL like:
227+
228+
```sql
229+
SELECT {col1}, {col2} FROM {tablename}
230+
```
231+
232+
While templating is not directly supported by SQL Formatter, the workaround
233+
is to use [paramTypes](docs/paramTypes.md) config option to treat these
234+
occurances of templating constructs as prepared-statement parameter-placeholders:
235+
236+
```js
237+
format('SELECT {col1}, {col2} FROM {tablename};', {
238+
paramTypes: { custom: [{ regex: String.raw`\{\w+\}` }] },
239+
});
240+
```
241+
242+
This won't work for all possible templating constructs,
243+
but should solve the most common use cases.
244+
224245
## The future
225246

226247
The development of this formatter is currently in maintenance mode.

0 commit comments

Comments
 (0)