@vanit-co/sql-ts 0.5.0 → 0.7.0

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.
Files changed (3) hide show
  1. package/README.md +11 -11
  2. package/dist/index.js +5 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,15 +8,15 @@ Supports **MySQL** (`?` placeholders, `` ` `` backtick identifiers) and **Postgr
8
8
 
9
9
  Writing raw SQL in TypeScript runs into a set of recurring friction points that this library addresses directly:
10
10
 
11
- - **Automatic identifier quoting** table and column names are interpolated as properly quoted identifiers (`` `name` `` for MySQL, `"name"` for PostgreSQL), never as bind parameters. No manual quoting, no dialect-specific escaping scattered across your codebase.
11
+ - **Automatic identifier quoting** - table and column names are interpolated as properly quoted identifiers (`` `name` `` for MySQL, `"name"` for PostgreSQL), never as bind parameters. No manual quoting, no dialect-specific escaping scattered across your codebase.
12
12
 
13
- - **Table alias and qualified column references** the `select` tag (and its aliases `groupBy`, `having`, `join`, `orderBy`, `where`) automatically expands schema tables as `"table" "alias"` and columns as `"alias"."column"`, so JOIN-heavy queries stay unambiguous without hand-writing every qualified reference.
13
+ - **Table alias and qualified column references** - the `select` tag (and its aliases `groupBy`, `having`, `join`, `orderBy`, `where`) automatically expands schema tables as `"table" "alias"` and columns as `"alias"."column"`, so JOIN-heavy queries stay unambiguous without hand-writing every qualified reference.
14
14
 
15
- - **Column alias expansion** `selectAs` goes further, rendering each column as `"alias"."column" as "alias_column"`. When querying multiple joined tables, result-set keys no longer collide.
15
+ - **Column alias expansion** - `selectAs` goes further, rendering each column as `"alias"."column" as "alias_column"`. When querying multiple joined tables, result-set keys no longer collide.
16
16
 
17
- - **`concat` and `empty` as a monoid** every tagged template and statement builder returns a `Fragment`. `concat` joins two fragments into one, and `empty` is the identity element. This lets you accumulate query fragments conditionally with `reduce`, compose them with `pipe`, or chain them with `.append` treating query construction as plain data transformation.
17
+ - **`concat` and `empty` as a monoid** - every tagged template and statement builder returns a `Fragment`. `concat` joins two fragments into one, and `empty` is the identity element. This lets you accumulate query fragments conditionally with `reduce`, compose them with `pipe`, or chain them with `.append` - treating query construction as plain data transformation.
18
18
 
19
- - **`all` and `pick` helpers** expand an entire table's columns or a chosen subset into a comma-separated list inside any tag, so `SELECT ${all(users, posts)}` replaces repetitive column lists without losing type safety.
19
+ - **`all` and `pick` helpers** - expand an entire table's columns or a chosen subset into a comma-separated list inside any tag, so `SELECT ${all(users, posts)}` replaces repetitive column lists without losing type safety.
20
20
 
21
21
  ## Installation
22
22
 
@@ -199,7 +199,7 @@ sa`SELECT ${u.email}`.text // SELECT "u"."email" as "u_email"
199
199
 
200
200
  ### `groupBy` (alias: `g`), `having` (alias: `h`), `join` (alias: `j`), `orderBy` (alias: `o`) and `where` (alias: `w`)
201
201
 
202
- These are all identical to `select`. They exist as semantic aliases so your query construction reads naturally each tag signals which SQL clause it belongs to.
202
+ These are all identical to `select`. They exist as semantic aliases so your query construction reads naturally - each tag signals which SQL clause it belongs to.
203
203
 
204
204
  ```ts
205
205
  import { select, join, j, where, w, groupBy, g, having, h, orderBy, o, schema } from '@vanit-co/sql-ts'
@@ -270,7 +270,7 @@ selectAs`SELECT ${pick(users.id, users.email)}`.text
270
270
 
271
271
  ### `as(column)`
272
272
 
273
- Returns the aliased column name as a plain string the same `prefix_name` string that `selectAs` writes into the SQL `AS` clause. Use this to read a column out of query results by its aliased key without repeating the string manually.
273
+ Returns the aliased column name as a plain string - the same `prefix_name` string that `selectAs` writes into the SQL `AS` clause. Use this to read a column out of query results by its aliased key without repeating the string manually.
274
274
 
275
275
  ```ts
276
276
  import { schema, as, selectAs, all } from '@vanit-co/sql-ts'
@@ -325,7 +325,7 @@ q2.values // [1, 'alice@example.com', 2, 'bob@example.com']
325
325
 
326
326
  ### `update(table, colsVals)`
327
327
 
328
- Builds a parameterised `UPDATE ... SET ...` statement (without a `WHERE` clause compose that separately using `concat`).
328
+ Builds a parameterised `UPDATE ... SET ...` statement (without a `WHERE` clause - compose that separately using `concat`).
329
329
 
330
330
  ```ts
331
331
  import { schema, update } from '@vanit-co/sql-ts'
@@ -348,7 +348,7 @@ q2.values // [99, 'updated@example.com']
348
348
 
349
349
  ### `concat`
350
350
 
351
- Joins two `Fragment` objects into one. `concat` is curried `concat(right)(left)` appends `right` after `left`.
351
+ Joins two `Fragment` objects into one. `concat` is curried - `concat(right)(left)` appends `right` after `left`.
352
352
 
353
353
  ```ts
354
354
  import { select, where, concat, schema } from '@vanit-co/sql-ts'
@@ -414,7 +414,7 @@ const q = pipe(
414
414
 
415
415
  ### `empty`
416
416
 
417
- An empty fragment. Acts as the identity element for `concat` useful as the starting value when accumulating fragments conditionally.
417
+ An empty fragment. Acts as the identity element for `concat` - useful as the starting value when accumulating fragments conditionally.
418
418
 
419
419
  ```ts
420
420
  import { pipe, reduce } from 'ramda'
@@ -501,7 +501,7 @@ named.values // [1]
501
501
  await client.query(named)
502
502
  ```
503
503
 
504
- `preparedStatementName` does not mutate the original result it returns a new object.
504
+ `preparedStatementName` does not mutate the original result - it returns a new object.
505
505
 
506
506
  ---
507
507
 
package/dist/index.js CHANGED
@@ -26,9 +26,9 @@ const stringfyIdentifierAndRaw = (quote = '') => (s) => {
26
26
  return [strings, binds, [...merge, ss, bs.content]];
27
27
  }
28
28
  else if (bs && bs[SYM_IDENTIFIER]) {
29
- return [strings, binds, [...merge, ss, (quote + bs.content + quote)]];
29
+ return [strings, binds, [...merge, ss, (quote + bs.content.replaceAll(quote, quote + quote) + quote)]];
30
30
  }
31
- else if (bs) {
31
+ else if (bs !== undefined) {
32
32
  return [[...strings, merge.join('') + ss], [...binds, bs], []];
33
33
  }
34
34
  else {
@@ -67,7 +67,7 @@ const result = (s) => ({
67
67
  return toPostgres(s).text;
68
68
  },
69
69
  get values() {
70
- return s.binds.filter((x) => !(x[SYM_RAW] || x[SYM_IDENTIFIER]));
70
+ return s.binds.filter((x) => !(x && (x[SYM_RAW] || x[SYM_IDENTIFIER])));
71
71
  }
72
72
  });
73
73
 
@@ -89,6 +89,8 @@ const identifier = (content) => ({ [SYM_IDENTIFIER]: true, content });
89
89
  const transformer = (table, column) => ([ss, bs]) => {
90
90
  if (bs === undefined)
91
91
  return [[ss]];
92
+ if (bs === null)
93
+ return [[ss, bs]];
92
94
  if (bs[SYM_TABLE])
93
95
  return table(ss, bs[SYM_TABLE]);
94
96
  if (bs[SYM_COLUMN])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanit-co/sql-ts",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
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",