@triptease/sql-template-postgres 0.15.13 → 0.18.16
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/index.d.ts +5 -1
- package/index.js +37 -2
- package/package.json +2 -2
- package/api.d.ts +0 -7
- package/api.js +0 -40
package/index.d.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { QueryConfig } from "pg";
|
|
2
|
+
import { Template } from '@triptease/sql-template';
|
|
3
|
+
export declare function debugQuery(sql: Template): string;
|
|
4
|
+
export declare function postgresSql(sql: Template): string;
|
|
5
|
+
export declare function query(template: Template): QueryConfig;
|
package/index.js
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.query = exports.postgresSql = exports.debugQuery = void 0;
|
|
4
|
+
const pg_1 = require("pg");
|
|
5
|
+
const sql_template_1 = require("@triptease/sql-template");
|
|
6
|
+
const escapeIdentifier = pg_1.Client.prototype.escapeIdentifier;
|
|
7
|
+
const escapeLiteral = pg_1.Client.prototype.escapeLiteral;
|
|
8
|
+
function debugQuery(sql) {
|
|
9
|
+
return sql.expressions.flatMap(e => {
|
|
10
|
+
if (e instanceof sql_template_1.Text)
|
|
11
|
+
return [e.text];
|
|
12
|
+
if (e instanceof sql_template_1.Identifier)
|
|
13
|
+
return [escapeIdentifier(e.identifier)];
|
|
14
|
+
if (e instanceof sql_template_1.Value)
|
|
15
|
+
return [typeof e.value === 'string' ? escapeLiteral(e.value) : e.value];
|
|
16
|
+
return [];
|
|
17
|
+
}).join('');
|
|
18
|
+
}
|
|
19
|
+
exports.debugQuery = debugQuery;
|
|
20
|
+
function postgresSql(sql) {
|
|
21
|
+
let count = 1;
|
|
22
|
+
return sql.expressions.flatMap(e => {
|
|
23
|
+
if (e instanceof sql_template_1.Text)
|
|
24
|
+
return [e.text];
|
|
25
|
+
if (e instanceof sql_template_1.Identifier)
|
|
26
|
+
return [escapeIdentifier(e.identifier)];
|
|
27
|
+
if (e instanceof sql_template_1.Value)
|
|
28
|
+
return '$' + count++;
|
|
29
|
+
return [];
|
|
30
|
+
}).join('');
|
|
31
|
+
}
|
|
32
|
+
exports.postgresSql = postgresSql;
|
|
33
|
+
function query(template) {
|
|
34
|
+
return {
|
|
35
|
+
text: postgresSql(template),
|
|
36
|
+
values: template.expressions.flatMap(e => e instanceof sql_template_1.Value ? [e.value] : [])
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.query = query;
|
|
5
40
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triptease/sql-template-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.16",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+ssh://git@github.com/triptease/sql-template.git"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"*.d.ts"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@triptease/sql-template": "0.
|
|
23
|
+
"@triptease/sql-template": "0.18.16",
|
|
24
24
|
"pg": "^8.7.1",
|
|
25
25
|
"tslib": "^2.3.1"
|
|
26
26
|
},
|
package/api.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { SqlTemplate } from "../../sql-template/src";
|
|
2
|
-
import { QueryConfig } from "pg";
|
|
3
|
-
export declare function postgresText(sql: SqlTemplate): string;
|
|
4
|
-
export declare function postgresQuery(sql: SqlTemplate): string;
|
|
5
|
-
export declare function id(identifier: string): SqlTemplate;
|
|
6
|
-
export declare function ids(identifiers: string[]): SqlTemplate;
|
|
7
|
-
export declare function queryConfig(template: SqlTemplate): QueryConfig;
|
package/api.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.queryConfig = exports.ids = exports.id = exports.postgresQuery = exports.postgresText = void 0;
|
|
4
|
-
const src_1 = require("../../sql-template/src");
|
|
5
|
-
const pg_1 = require("pg");
|
|
6
|
-
const CompositeTemplate_1 = require("../../sql-template/src/CompositeTemplate");
|
|
7
|
-
const escapeIdentifier = pg_1.Client.prototype.escapeIdentifier;
|
|
8
|
-
const escapeLiteral = pg_1.Client.prototype.escapeLiteral;
|
|
9
|
-
function postgresText(sql) {
|
|
10
|
-
let count = 1;
|
|
11
|
-
return sql.text.replace(/\?/g, () => `\$${count++}`);
|
|
12
|
-
}
|
|
13
|
-
exports.postgresText = postgresText;
|
|
14
|
-
// Debug only
|
|
15
|
-
function postgresQuery(sql) {
|
|
16
|
-
const values = [...sql.values];
|
|
17
|
-
return sql.text.replace(/\?/g, () => {
|
|
18
|
-
const value = values.shift();
|
|
19
|
-
if (typeof value === 'string')
|
|
20
|
-
return escapeLiteral(value);
|
|
21
|
-
return value;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
exports.postgresQuery = postgresQuery;
|
|
25
|
-
function id(identifier) {
|
|
26
|
-
return (0, src_1.sqlTemplate)(escapeIdentifier(identifier), []);
|
|
27
|
-
}
|
|
28
|
-
exports.id = id;
|
|
29
|
-
function ids(identifiers) {
|
|
30
|
-
return (0, CompositeTemplate_1.compose)(identifiers.map(id));
|
|
31
|
-
}
|
|
32
|
-
exports.ids = ids;
|
|
33
|
-
function queryConfig(template) {
|
|
34
|
-
return {
|
|
35
|
-
text: postgresText(template),
|
|
36
|
-
values: [...template.values]
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
exports.queryConfig = queryConfig;
|
|
40
|
-
//# sourceMappingURL=api.js.map
|