@triptease/sql-template-postgres 0.6.6 → 0.14.12
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/api.d.ts +2 -0
- package/api.js +8 -1
- package/index.d.ts +0 -1
- package/index.js +0 -3
- package/package.json +2 -2
- package/PostgresClient.d.ts +0 -9
- package/PostgresClient.js +0 -33
package/api.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SqlTemplate } from "../../sql-template/src";
|
|
2
|
+
import { QueryConfig } from "pg";
|
|
2
3
|
export declare function postgresText(sql: SqlTemplate): string;
|
|
3
4
|
export declare function postgresQuery(sql: SqlTemplate): string;
|
|
4
5
|
export declare function id(identifier: string): SqlTemplate;
|
|
5
6
|
export declare function ids(identifiers: string[]): SqlTemplate;
|
|
7
|
+
export declare function queryConfig(template: SqlTemplate): QueryConfig;
|
package/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ids = exports.id = exports.postgresQuery = exports.postgresText = void 0;
|
|
3
|
+
exports.queryConfig = exports.ids = exports.id = exports.postgresQuery = exports.postgresText = void 0;
|
|
4
4
|
const src_1 = require("../../sql-template/src");
|
|
5
5
|
const pg_1 = require("pg");
|
|
6
6
|
const CompositeTemplate_1 = require("../../sql-template/src/CompositeTemplate");
|
|
@@ -30,4 +30,11 @@ function ids(identifiers) {
|
|
|
30
30
|
return (0, CompositeTemplate_1.compose)(identifiers.map(id));
|
|
31
31
|
}
|
|
32
32
|
exports.ids = ids;
|
|
33
|
+
function queryConfig(template) {
|
|
34
|
+
return {
|
|
35
|
+
text: postgresText(template),
|
|
36
|
+
values: [...template.values]
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.queryConfig = queryConfig;
|
|
33
40
|
//# sourceMappingURL=api.js.map
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PostgresClient = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
4
|
(0, tslib_1.__exportStar)(require("./api"), exports);
|
|
6
|
-
var PostgresClient_1 = require("./PostgresClient");
|
|
7
|
-
Object.defineProperty(exports, "PostgresClient", { enumerable: true, get: function () { return PostgresClient_1.PostgresClient; } });
|
|
8
5
|
//# 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.14.12",
|
|
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.14.12",
|
|
24
24
|
"pg": "^8.7.1",
|
|
25
25
|
"tslib": "^2.3.1"
|
|
26
26
|
},
|
package/PostgresClient.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SimpleObject, SqlClient, SqlTemplate } from "../../sql-template/src";
|
|
2
|
-
import { PoolConfig } from "pg";
|
|
3
|
-
export declare class PostgresClient implements SqlClient {
|
|
4
|
-
private logger;
|
|
5
|
-
private pool;
|
|
6
|
-
constructor(connectionDetails: PoolConfig, logger?: (sql: string) => void);
|
|
7
|
-
query(sqlFragment: SqlTemplate): Promise<SimpleObject[]>;
|
|
8
|
-
close(): Promise<void>;
|
|
9
|
-
}
|
package/PostgresClient.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PostgresClient = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const pg_1 = require("pg");
|
|
6
|
-
const api_1 = require("./api");
|
|
7
|
-
class PostgresClient {
|
|
8
|
-
constructor(connectionDetails, logger = (sql) => console.log('PostgresClient.query', sql)) {
|
|
9
|
-
this.logger = logger;
|
|
10
|
-
this.pool = new pg_1.Pool(connectionDetails);
|
|
11
|
-
}
|
|
12
|
-
query(sqlFragment) {
|
|
13
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
14
|
-
const client = yield this.pool.connect();
|
|
15
|
-
try {
|
|
16
|
-
const sql = (0, api_1.postgresText)(sqlFragment);
|
|
17
|
-
this.logger(sql);
|
|
18
|
-
const { rows } = yield client.query(sql, [...sqlFragment.values]);
|
|
19
|
-
return rows;
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
client.release();
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
close() {
|
|
27
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
28
|
-
return this.pool.end();
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.PostgresClient = PostgresClient;
|
|
33
|
-
//# sourceMappingURL=PostgresClient.js.map
|