You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+26-6
Original file line number
Diff line number
Diff line change
@@ -35,17 +35,37 @@ const query = sql`SELECT * FROM books WHERE author_id IN (${nested})`;
35
35
sql`SELECT * FROM books ${hasIds?sql`WHERE ids IN (${join(ids)})`:empty}`;
36
36
```
37
37
38
-
## Related
38
+
### Join
39
+
40
+
Accepts an array of values and returns a SQL instance with the values joined by the separator. E.g.
41
+
42
+
```js
43
+
constquery=join([1, 2, 3]);
39
44
40
-
The main difference between this module and others is first-class TypeScript. There's also the `raw`, `join` and `empty` helpers. Specific differences are documented below:
Accepts a string and returns a SQL instance, useful if you want some part of the SQL to be dynamic.
43
52
44
-
Promotes mutation via chained methods and lacks nesting SQL statements. The idea to support both `sql` and `text` for `mysql` and `pg` compatibility came from here.
53
+
```js
54
+
raw("SELECT"); // == sql`SELECT`
55
+
```
56
+
57
+
**Do not** accept user input to `raw`, this will create a SQL injection vulnerability.
58
+
59
+
### Empty
60
+
61
+
Simple placeholder value for an empty SQL string. Equivalent to `raw("")`.
Some other modules exist that do something similar:
47
66
48
-
Missing TypeScript and MySQL support. This is the API I envisioned before starting development and, by supporting `pg` only, it has the ability to [dedupe `values`](https://github.com/XeCycle/pg-template-tag/issues/5#issuecomment-386875336). Supporting MySQL makes deduping impossible, because of `?` placeholders instead of `$<num>`, so I decided that was a premature optimisation here and opted to keep `mysql` support here instead.
67
+
-[`sql-template-strings`](https://github.com/felixfbecker/node-sql-template-strings): promotes mutation via chained methods and lacks nesting SQL statements. The idea to support `sql` and `text` properties for dual `mysql` and `pg` compatibility came from here.
68
+
-[`pg-template-tag`](https://github.com/XeCycle/pg-template-tag): missing TypeScript and MySQL support. This is the API I envisioned before writing this library, and by supporting `pg` only it has the ability to [dedupe `values`](https://github.com/XeCycle/pg-template-tag/issues/5#issuecomment-386875336).
0 commit comments