@triptease/sql-template 0.20.21 → 0.21.22

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 (2) hide show
  1. package/README.md +35 -8
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -6,24 +6,51 @@ This is yet another SQL tagged template for Typescript/Javascript
6
6
 
7
7
  * Typescript first
8
8
  * Functional/Immutable
9
- * Super simple implementaion (the main SQL function is [3 lines of code](https://github.com/triptease/sql-template/blob/master/sql-template/src/SQL.ts#L5))
10
- * Plugable to any DB (currently has a Postgres function in @triptease\sql-template-postgres)
9
+ * Super simple implementation (the main SQL function is [3 lines of code](https://github.com/triptease/sql-template/blob/master/sql-template/src/SQL.ts#L5))
10
+ * Full escaping of identifiers and values
11
+ * Plugable to any DB (currently only Postgres @triptease\sql-template-postgres )
11
12
  * Automatic support for prepareStatement naming (Postgres)
12
13
 
13
14
  ## Installation
14
15
 
15
- ```
16
+ ```shell
16
17
  npm install @triptease\sql-template @triptease\sql-template-postgres
17
18
  ```
18
19
 
19
20
  ## Usage
20
21
 
21
- ```
22
- import {SQL} from "@triptease/sql-template";
22
+ ```javascript
23
+ import {SQL, id} from "@triptease/sql-template";
23
24
  import {statement} from "@triptease/sql-template-postgres";
24
25
 
25
- pg.query(statement(SQL`select * from user where name = ${name}`));
26
-
26
+ client.query(statement(SQL`select * from ${id(table)} where name = ${name}`));
27
27
  ```
28
28
 
29
- WIP more to come
29
+ ## Cheatsheet
30
+
31
+ ### Core (@triptease/sql-template)
32
+
33
+ | function | Description |
34
+ |------------------------------------------------|----------------------------------------------------------------------|
35
+ | `SQL` | The main function to create tagged templates for SQL (*DB agnostic*) |
36
+ | `text` (alias `raw`) | Input raw SQL without any escaping (*use with care*) |
37
+ | `id` / `ids` | Input dynamic identifiers into SQL (*escaped as needed*) |
38
+ | `value` (optional) / `values` (alias `spread`) | Input one or more values into SQL (*escaped as needed*) |
39
+
40
+
41
+ ### Postgres (@triptease/sql-template-postgres)
42
+
43
+ | function | Description |
44
+ |------------------------------------------------|---------------------------------------------------------------------|
45
+ | `statement` | Converts DB agnostic `SQL` template into postgres statement |
46
+ | `prepareStatement` | Converts DB agnostic `SQL` template into postgres prepare statement |
47
+ | `debugQuery` | Used to debug a query (*use with care*) |
48
+
49
+ *use with care -> Used incorrectly you can open yourself up to SQL injection*
50
+
51
+
52
+ ### Extending
53
+
54
+ It is incredibly simple to extend to other DBs, have a look at the [postgres implementation](https://github.com/triptease/sql-template/blob/master/sql-template-postgres/src/index.ts#L17).
55
+
56
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triptease/sql-template",
3
- "version": "0.20.21",
3
+ "version": "0.21.22",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+ssh://git@github.com/triptease/sql-template.git"
@@ -23,5 +23,5 @@
23
23
  "tslib": "^2.3.1"
24
24
  },
25
25
  "scripts": {},
26
- "readme": "# Sql Template\r\n\r\nThis is yet another SQL tagged template for Typescript/Javascript\r\n\r\n## Why another library?\r\n\r\n* Typescript first\r\n* Functional/Immutable\r\n* Super simple implementaion (the main SQL function is [3 lines of code](https://github.com/triptease/sql-template/blob/master/sql-template/src/SQL.ts#L5))\r\n* Plugable to any DB (currently has a Postgres function in @triptease\\sql-template-postgres)\r\n* Automatic support for prepareStatement naming (Postgres)\r\n\r\n## Installation\r\n\r\n```\r\nnpm install @triptease\\sql-template @triptease\\sql-template-postgres\r\n```\r\n\r\n## Usage\r\n\r\n```\r\nimport {SQL} from \"@triptease/sql-template\";\r\nimport {statement} from \"@triptease/sql-template-postgres\";\r\n\r\npg.query(statement(SQL`select * from user where name = ${name}`));\r\n\r\n```\r\n\r\nWIP more to come\r\n"
26
+ "readme": "# Sql Template\r\n\r\nThis is yet another SQL tagged template for Typescript/Javascript\r\n\r\n## Why another library?\r\n\r\n* Typescript first\r\n* Functional/Immutable\r\n* Super simple implementation (the main SQL function is [3 lines of code](https://github.com/triptease/sql-template/blob/master/sql-template/src/SQL.ts#L5))\r\n* Full escaping of identifiers and values\r\n* Plugable to any DB (currently only Postgres @triptease\\sql-template-postgres )\r\n* Automatic support for prepareStatement naming (Postgres)\r\n\r\n## Installation\r\n\r\n```shell\r\nnpm install @triptease\\sql-template @triptease\\sql-template-postgres\r\n```\r\n\r\n## Usage\r\n\r\n```javascript\r\nimport {SQL, id} from \"@triptease/sql-template\";\r\nimport {statement} from \"@triptease/sql-template-postgres\";\r\n\r\nclient.query(statement(SQL`select * from ${id(table)} where name = ${name}`));\r\n```\r\n\r\n## Cheatsheet\r\n\r\n### Core (@triptease/sql-template) \r\n\r\n| function | Description |\r\n|------------------------------------------------|----------------------------------------------------------------------|\r\n| `SQL` | The main function to create tagged templates for SQL (*DB agnostic*) |\r\n| `text` (alias `raw`) | Input raw SQL without any escaping (*use with care*) |\r\n | `id` / `ids` | Input dynamic identifiers into SQL (*escaped as needed*) |\r\n | `value` (optional) / `values` (alias `spread`) | Input one or more values into SQL (*escaped as needed*) |\r\n\r\n\r\n### Postgres (@triptease/sql-template-postgres)\r\n\r\n| function | Description |\r\n|------------------------------------------------|---------------------------------------------------------------------|\r\n| `statement` | Converts DB agnostic `SQL` template into postgres statement |\r\n| `prepareStatement` | Converts DB agnostic `SQL` template into postgres prepare statement |\r\n| `debugQuery` | Used to debug a query (*use with care*) |\r\n\r\n*use with care -> Used incorrectly you can open yourself up to SQL injection*\r\n\r\n\r\n### Extending\r\n\r\nIt is incredibly simple to extend to other DBs, have a look at the [postgres implementation](https://github.com/triptease/sql-template/blob/master/sql-template-postgres/src/index.ts#L17). \r\n\r\n\r\n"
27
27
  }