@vanit-co/sql-ts 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A TypeScript SQL query builder using tagged template literals. Write plain SQL with safe, automatic parameter binding and properly quoted identifiers. No DSL to learn, no magic, no ORM.
|
|
4
4
|
|
|
5
|
-
Supports **MySQL** (`?` placeholders, `` ` `` backtick identifiers)
|
|
5
|
+
Supports **MySQL** (`?` placeholders, `` ` `` backtick identifiers), **PostgreSQL** (`$n` placeholders, `"` double-quote identifiers) and **SQLite** (through the MySQL format, see [Result object](#result-object)) out of the box.
|
|
6
6
|
|
|
7
7
|
## Why this library?
|
|
8
8
|
|
|
@@ -136,7 +136,7 @@ Every template tag and statement builder returns a `Result` object with three pr
|
|
|
136
136
|
|
|
137
137
|
| property | description |
|
|
138
138
|
|----------|-------------|
|
|
139
|
-
| `.sql` | Query string in MySQL format (`?` placeholders, backtick-quoted identifiers) |
|
|
139
|
+
| `.sql` | Query string in MySQL format (`?` placeholders, backtick-quoted identifiers), also used for SQLite |
|
|
140
140
|
| `.text` | Query string in PostgreSQL format (`$n` placeholders, double-quote identifiers) |
|
|
141
141
|
| `.values` | Array of bind values in order, ready to pass to your database driver |
|
|
142
142
|
|
|
@@ -148,8 +148,13 @@ await client.query(query)
|
|
|
148
148
|
|
|
149
149
|
// mysql2
|
|
150
150
|
await connection.query(query)
|
|
151
|
+
|
|
152
|
+
// better-sqlite3 / node:sqlite
|
|
153
|
+
db.prepare(query.sql).all(...query.values)
|
|
151
154
|
```
|
|
152
155
|
|
|
156
|
+
SQLite accepts backtick-quoted identifiers and `?` placeholders, so use `.sql` with it. Do not use `.text`: SQLite reads `$1` as a named parameter, so positional values won't bind.
|
|
157
|
+
|
|
153
158
|
---
|
|
154
159
|
|
|
155
160
|
## Template tag functions
|
|
@@ -351,7 +356,7 @@ q3.text // insert into "users" ("id" ,"email") values (nextval('users_id_seq'
|
|
|
351
356
|
q3.values // ['alice@example.com']
|
|
352
357
|
```
|
|
353
358
|
|
|
354
|
-
Column objects used as values are resolved to quoted identifiers rather than bound. They render unprefixed, since the statement has no alias in scope.
|
|
359
|
+
Column objects used as values are resolved to quoted identifiers rather than bound. They render unprefixed, since the statement has no alias in scope. Referencing a column inside `values (...)` is only accepted by MySQL; PostgreSQL and SQLite reject it.
|
|
355
360
|
|
|
356
361
|
### `update(table, colsVals)`
|
|
357
362
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanit-co/sql-ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A TypeScript SQL query builder using tagged template literals. Write plain SQL with safe, automatic parameter binding and properly quoted identifiers. No DSL to learn, no magic, no ORM.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
"postgres",
|
|
38
38
|
"pg",
|
|
39
39
|
"mysql",
|
|
40
|
-
"mysql2"
|
|
40
|
+
"mysql2",
|
|
41
|
+
"sqlite",
|
|
42
|
+
"better-sqlite3"
|
|
41
43
|
],
|
|
42
44
|
"author": "Geovanny Silva",
|
|
43
45
|
"license": "MIT",
|