@triptease/sql-template 0.20.21 → 0.24.25
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/Identifier.d.ts +1 -1
- package/README.md +36 -9
- package/Template.d.ts +2 -2
- package/Text.d.ts +1 -1
- package/Value.d.ts +1 -1
- package/package.json +2 -2
package/Identifier.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Expression } from "./Expression";
|
|
2
2
|
import { Template } from "./Template";
|
|
3
3
|
export declare class Identifier extends Expression {
|
|
4
|
-
identifier: string;
|
|
4
|
+
readonly identifier: string;
|
|
5
5
|
constructor(identifier: string);
|
|
6
6
|
}
|
|
7
7
|
export declare function id(identifier: string): Identifier;
|
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
|
|
10
|
-
*
|
|
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
|
-
npm install @triptease
|
|
16
|
+
```shell
|
|
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
|
-
|
|
26
|
-
|
|
26
|
+
client.query(statement(SQL`select * from ${id(table)} where name = ${name}`));
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
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/Template.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Expression } from "./Expression";
|
|
2
2
|
export declare class Template extends Expression {
|
|
3
|
-
expressions: Expression
|
|
4
|
-
constructor(expressions: Expression
|
|
3
|
+
readonly expressions: ReadonlyArray<Expression>;
|
|
4
|
+
constructor(expressions: ReadonlyArray<Expression>);
|
|
5
5
|
}
|
|
6
6
|
export declare function template(...expressions: Expression[]): Template;
|
package/Text.d.ts
CHANGED
package/Value.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triptease/sql-template",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.25",
|
|
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
|
|
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
|
}
|