@technicity/data-service-generator 0.2.8 → 0.4.1

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 (43) hide show
  1. package/dist/CustomError.d.ts +3 -0
  2. package/dist/SDKNotFoundError.d.ts +4 -0
  3. package/dist/addNullFallbacks.d.ts +1 -0
  4. package/dist/addNullFallbacks.js +3 -0
  5. package/dist/cursor.d.ts +2 -0
  6. package/dist/generate.d.ts +20 -0
  7. package/dist/generate.js +100 -111
  8. package/dist/getDateTimeStringMySQL.d.ts +1 -0
  9. package/dist/getDuplicates.d.ts +1 -0
  10. package/dist/getOrderBy.d.ts +5 -0
  11. package/dist/getOrderBy.js +54 -0
  12. package/dist/getSqlAst.d.ts +2 -0
  13. package/dist/getSqlAst.js +4 -34
  14. package/dist/getWhere.d.ts +2 -0
  15. package/dist/getWhere.js +1 -2
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +3 -1
  18. package/dist/isNotNullOrUndefined.d.ts +1 -0
  19. package/dist/ksql.d.ts +9 -0
  20. package/dist/ksql.js +53 -0
  21. package/dist/mysql.d.ts +2 -0
  22. package/dist/mysql.js +0 -3
  23. package/dist/runTransforms.d.ts +2 -0
  24. package/dist/runtime/IRuntime.d.ts +47 -0
  25. package/dist/{IDialect.js → runtime/IRuntime.js} +0 -0
  26. package/dist/runtime/RuntimeKSQL.d.ts +19 -0
  27. package/dist/runtime/RuntimeKSQL.js +128 -0
  28. package/dist/runtime/RuntimeMSSQL.d.ts +21 -0
  29. package/dist/runtime/RuntimeMSSQL.js +88 -0
  30. package/dist/runtime/RuntimeMySQL.d.ts +20 -0
  31. package/dist/runtime/RuntimeMySQL.js +117 -0
  32. package/dist/runtime/__MSSQL.d.ts +7 -0
  33. package/dist/runtime/__MSSQL.js +46 -0
  34. package/dist/runtime/__shared.d.ts +32 -0
  35. package/dist/{runtime.js → runtime/__shared.js} +213 -230
  36. package/dist/runtime/__typeCastMSSQL.d.ts +3 -0
  37. package/dist/runtime/__typeCastMSSQL.js +40 -0
  38. package/dist/stringifyWhere.d.ts +18 -0
  39. package/dist/stringifyWhere.js +41 -50
  40. package/dist/types.d.ts +142 -0
  41. package/dist/types.js +2 -0
  42. package/package.json +1 -1
  43. package/dist/driverOpts.js +0 -54
package/dist/ksql.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KSQL = void 0;
4
+ const http2 = require("http2");
5
+ class KSQL {
6
+ constructor(options) {
7
+ this.hostname = options.hostname;
8
+ this.port = options.port;
9
+ }
10
+ async streamQuery(s) {
11
+ return new Promise((resolve, reject) => {
12
+ const reqBody = JSON.stringify({
13
+ sql: s,
14
+ properties: {
15
+ "ksql.streams.auto.offset.reset": "earliest",
16
+ "ksql.query.pull.table.scan.enabled": true,
17
+ },
18
+ });
19
+ const client = http2.connect(`http://${this.hostname}:${this.port}`);
20
+ const req = client.request({
21
+ [http2.constants.HTTP2_HEADER_SCHEME]: "https",
22
+ "Content-Type": "application/json",
23
+ "Content-Length": reqBody.length,
24
+ ":method": "POST",
25
+ ":path": `/query-stream`,
26
+ });
27
+ req.setEncoding("utf8");
28
+ let columnNames = [];
29
+ let rows = [];
30
+ req.on("data", (d) => {
31
+ const resData = JSON.parse(d);
32
+ if (resData.error_code) {
33
+ return reject(new Error(resData.message));
34
+ }
35
+ if (resData.columnNames) {
36
+ columnNames = resData.columnNames;
37
+ }
38
+ else {
39
+ let out = {};
40
+ resData.forEach((rd, i) => {
41
+ out[columnNames[i]] = rd;
42
+ });
43
+ rows.push(out);
44
+ }
45
+ });
46
+ req.on("close", () => resolve(rows));
47
+ req.on("error", (error) => reject(error));
48
+ req.write(reqBody);
49
+ req.end();
50
+ });
51
+ }
52
+ }
53
+ exports.KSQL = KSQL;
@@ -0,0 +1,2 @@
1
+ export function init(opts: any): void;
2
+ export function query(...args: any[]): any;
package/dist/mysql.js CHANGED
@@ -14,9 +14,6 @@ async function getConnection() {
14
14
  .disposer((connection) => connection.release());
15
15
  }
16
16
  // http://bluebirdjs.com/docs/api/promise.using.html
17
- // Don't use `async` keyword. Need to return Bluebird promise for compat,
18
- // since there are services doing e.g. promise.map and promise.tap, which are
19
- // specific to Bluebird.
20
17
  function query(...args) {
21
18
  return Promise.using(getConnection(), (connection) => connection.queryAsync(...args));
22
19
  }
@@ -0,0 +1,2 @@
1
+ import type { IGetSQLASTInput } from "./types";
2
+ export declare function runTransforms(data: any, fields: IGetSQLASTInput["fields"]): void;
@@ -0,0 +1,47 @@
1
+ import { IArtifacts, IGetSQLASTInput } from "../types";
2
+ export interface IRuntime {
3
+ resolve(input: TResolveInput): Promise<any>;
4
+ post(input: TPostInput): Promise<any>;
5
+ patch(input: TPatchInput): Promise<any>;
6
+ patchList(input: TPatchListInput): Promise<any>;
7
+ del(input: TDelInput): Promise<any>;
8
+ deleteList(input: TDeleteListInput): Promise<any>;
9
+ whereNeedsProcessing(where: any): boolean;
10
+ _prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<any>;
11
+ }
12
+ export declare type TResolveInput = Omit<IGetSQLASTInput, "getWhere" | "where" | "dialect"> & {
13
+ fields: IGetSQLASTInput["fields"] | undefined;
14
+ kind?: "list" | "listPaginated";
15
+ };
16
+ export declare type TPostInput = {
17
+ table: TResolveInput["table"];
18
+ data: any;
19
+ artifacts: TResolveInput["artifacts"];
20
+ fields: TResolveInput["fields"];
21
+ fieldName: TResolveInput["fieldName"];
22
+ };
23
+ export declare type TPatchInput = {
24
+ table: TResolveInput["table"];
25
+ args: TResolveInput["args"];
26
+ data: any;
27
+ artifacts: TResolveInput["artifacts"];
28
+ fields: TResolveInput["fields"];
29
+ fieldName: TResolveInput["fieldName"];
30
+ };
31
+ export declare type TPatchListInput = {
32
+ table: TResolveInput["table"];
33
+ args: TResolveInput["args"];
34
+ data: any;
35
+ artifacts: TResolveInput["artifacts"];
36
+ fields: TResolveInput["fields"];
37
+ fieldName: TResolveInput["fieldName"];
38
+ };
39
+ export declare type TDelInput = {
40
+ table: TResolveInput["table"];
41
+ args: TResolveInput["args"];
42
+ };
43
+ export declare type TDeleteListInput = {
44
+ table: TResolveInput["table"];
45
+ args: TResolveInput["args"];
46
+ artifacts: IArtifacts;
47
+ };
File without changes
@@ -0,0 +1,19 @@
1
+ import type { IRuntime, TResolveInput, TPatchInput, TPatchListInput, TPostInput, TDelInput, TDeleteListInput } from "./IRuntime";
2
+ import type { IArtifacts, ISupplementClientOpts } from "../types";
3
+ import { KSQL } from "../ksql";
4
+ import { MSSQL } from "./__MSSQL";
5
+ export declare class RuntimeKSQL implements IRuntime {
6
+ #private;
7
+ constructor(clientOpts: ConstructorParameters<typeof KSQL>[0], otherOpts: {
8
+ mssql: ConstructorParameters<typeof MSSQL>[0];
9
+ supplementClientOpts?: ISupplementClientOpts;
10
+ }, artifacts: IArtifacts);
11
+ resolve(input: TResolveInput): Promise<any>;
12
+ post(input: TPostInput): Promise<void>;
13
+ patch(input: TPatchInput): Promise<void>;
14
+ patchList(input: TPatchListInput): Promise<void>;
15
+ del(input: TDelInput): Promise<void>;
16
+ deleteList(input: TDeleteListInput): Promise<void>;
17
+ whereNeedsProcessing(where: any): boolean;
18
+ _prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
19
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to set private field on non-instance");
5
+ }
6
+ privateMap.set(receiver, value);
7
+ return value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to get private field on non-instance");
12
+ }
13
+ return privateMap.get(receiver);
14
+ };
15
+ var _ksql, _mssqlClient, _tableKeyMap;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RuntimeKSQL = void 0;
18
+ const SqlString = require("sqlstring");
19
+ const __shared_1 = require("./__shared");
20
+ const getWhere_1 = require("../getWhere");
21
+ const ksql_1 = require("../ksql");
22
+ const SDKNotFoundError_1 = require("../SDKNotFoundError");
23
+ const __MSSQL_1 = require("./__MSSQL");
24
+ const __typeCastMSSQL_1 = require("./__typeCastMSSQL");
25
+ class RuntimeKSQL {
26
+ constructor(clientOpts, otherOpts, artifacts) {
27
+ _ksql.set(this, void 0);
28
+ _mssqlClient.set(this, void 0);
29
+ _tableKeyMap.set(this, void 0);
30
+ __classPrivateFieldSet(this, _ksql, new ksql_1.KSQL(clientOpts));
31
+ __classPrivateFieldSet(this, _mssqlClient, new __MSSQL_1.MSSQL(otherOpts.mssql, otherOpts?.supplementClientOpts ? __typeCastMSSQL_1.typeCastMSSQL() : undefined));
32
+ __classPrivateFieldSet(this, _tableKeyMap, {});
33
+ for (let table in artifacts) {
34
+ let map = {};
35
+ for (let kk of artifacts[table].scalarFields) {
36
+ map[kk.toLocaleUpperCase()] = kk;
37
+ }
38
+ __classPrivateFieldGet(this, _tableKeyMap)[table] = map;
39
+ }
40
+ }
41
+ async resolve(input) {
42
+ if (input.kind === "list" || input.kind === "listPaginated") {
43
+ const primaryKey = input.artifacts[input.table].primaryKey;
44
+ // Overwrite
45
+ input.fields = [primaryKey];
46
+ const resolved = await __shared_1.resolve(input, __classPrivateFieldGet(this, _mssqlClient).dbCall.bind(__classPrivateFieldGet(this, _mssqlClient)), __classPrivateFieldGet(this, _mssqlClient).formatQuery.bind(__classPrivateFieldGet(this, _mssqlClient)), { dialect: "mssql" });
47
+ const keys = input.kind === "list"
48
+ ? resolved.map((x) => x[primaryKey])
49
+ : resolved.results.map((x) => x[primaryKey]);
50
+ if (keys.length === 0) {
51
+ return resolved;
52
+ }
53
+ const sql = SqlString.format("SELECT * FROM ?? WHERE ?? IN (?);", [
54
+ getKSQLTablename(input.table),
55
+ primaryKey.toLocaleUpperCase(),
56
+ keys,
57
+ ]);
58
+ const results = await __classPrivateFieldGet(this, _ksql).streamQuery(sql);
59
+ for (let x of results) {
60
+ mapKeys(x, __classPrivateFieldGet(this, _tableKeyMap)[input.table]);
61
+ }
62
+ if (input.kind == "list") {
63
+ return results;
64
+ }
65
+ resolved.results = results;
66
+ return resolved;
67
+ }
68
+ else {
69
+ const table = input.table;
70
+ const tableKSQL = getKSQLTablename(input.table);
71
+ if (input.args?.$where) {
72
+ for (let k in input.args.$where) {
73
+ input.args.$where[k.toLocaleUpperCase()] = input.args.$where[k];
74
+ delete input.args.$where[k];
75
+ }
76
+ }
77
+ const where = getWhere_1.getWhere(tableKSQL, input.args, "mysql");
78
+ if (!where) {
79
+ throw new Error("Invalid $where");
80
+ }
81
+ const sql = SqlString.format(`SELECT * FROM ?? WHERE ${where};`, [
82
+ tableKSQL,
83
+ ]);
84
+ let out = await __classPrivateFieldGet(this, _ksql).streamQuery(sql).then((xs) => xs[0]);
85
+ if (out == null) {
86
+ throw new SDKNotFoundError_1.SDKNotFoundError();
87
+ }
88
+ mapKeys(out, __classPrivateFieldGet(this, _tableKeyMap)[table]);
89
+ return out;
90
+ }
91
+ }
92
+ async post(input) {
93
+ throw new Error("Not implemented.");
94
+ }
95
+ async patch(input) {
96
+ throw new Error("Not implemented.");
97
+ }
98
+ async patchList(input) {
99
+ throw new Error("Not implemented.");
100
+ }
101
+ async del(input) {
102
+ throw new Error("Not implemented.");
103
+ }
104
+ async deleteList(input) {
105
+ throw new Error("Not implemented.");
106
+ }
107
+ whereNeedsProcessing(where) {
108
+ return __shared_1.whereNeedsProcessing(where);
109
+ }
110
+ async _prepareWhere(artifacts, table, data) {
111
+ return __shared_1._prepareWhere(artifacts, table, data, __classPrivateFieldGet(this, _mssqlClient).dbCall.bind(__classPrivateFieldGet(this, _mssqlClient)), __classPrivateFieldGet(this, _mssqlClient).formatQuery.bind(__classPrivateFieldGet(this, _mssqlClient)));
112
+ }
113
+ }
114
+ exports.RuntimeKSQL = RuntimeKSQL;
115
+ _ksql = new WeakMap(), _mssqlClient = new WeakMap(), _tableKeyMap = new WeakMap();
116
+ function getKSQLTablename(tablename) {
117
+ return `${tablename.toLocaleUpperCase()}_TAB`;
118
+ }
119
+ // Mutates item
120
+ function mapKeys(item, keyMap) {
121
+ for (let k in item) {
122
+ const v = keyMap[k];
123
+ if (v) {
124
+ item[v] = item[k];
125
+ delete item[k];
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,21 @@
1
+ import * as mssql from "mssql";
2
+ import type { IRuntime, TResolveInput, TPatchInput, TPatchListInput, TPostInput, TDelInput, TDeleteListInput } from "./IRuntime";
3
+ import type { IArtifacts, ISupplementClientOpts } from "../types";
4
+ import { typeCastMSSQL } from "./__typeCastMSSQL";
5
+ export declare class RuntimeMSSQL implements IRuntime {
6
+ #private;
7
+ constructor(clientOpts: mssql.config, otherOpts: {
8
+ supplementClientOpts?: ISupplementClientOpts;
9
+ typeCast?: Parameters<typeof typeCastMSSQL>[0];
10
+ }, artifacts: IArtifacts);
11
+ resolve(input: TResolveInput): Promise<any>;
12
+ post(input: TPostInput): Promise<any>;
13
+ patch(input: TPatchInput): Promise<any>;
14
+ patchList(input: TPatchListInput): Promise<any>;
15
+ del(input: TDelInput): Promise<boolean>;
16
+ deleteList(input: TDeleteListInput): Promise<boolean>;
17
+ whereNeedsProcessing(where: any): boolean;
18
+ _prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
19
+ private dbCall;
20
+ private formatQuery;
21
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to set private field on non-instance");
5
+ }
6
+ privateMap.set(receiver, value);
7
+ return value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to get private field on non-instance");
12
+ }
13
+ return privateMap.get(receiver);
14
+ };
15
+ var _dialect, _mssqlClient;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RuntimeMSSQL = void 0;
18
+ const __shared_1 = require("./__shared");
19
+ const __MSSQL_1 = require("./__MSSQL");
20
+ const __typeCastMSSQL_1 = require("./__typeCastMSSQL");
21
+ class RuntimeMSSQL {
22
+ constructor(clientOpts, otherOpts, artifacts) {
23
+ _dialect.set(this, "mssql");
24
+ _mssqlClient.set(this, void 0);
25
+ __classPrivateFieldSet(this, _mssqlClient, new __MSSQL_1.MSSQL(clientOpts, otherOpts?.supplementClientOpts
26
+ ? __typeCastMSSQL_1.typeCastMSSQL(otherOpts?.typeCast)
27
+ : undefined));
28
+ }
29
+ async resolve(input) {
30
+ return __shared_1.resolve(input, this.dbCall.bind(this), this.formatQuery.bind(this), {
31
+ dialect: __classPrivateFieldGet(this, _dialect),
32
+ });
33
+ }
34
+ async post(input) {
35
+ return __shared_1.post({
36
+ ...input,
37
+ dbCall: this.dbCall.bind(this),
38
+ formatQuery: this.formatQuery.bind(this),
39
+ dialect: __classPrivateFieldGet(this, _dialect),
40
+ });
41
+ }
42
+ async patch(input) {
43
+ return __shared_1.patch({
44
+ ...input,
45
+ dbCall: this.dbCall.bind(this),
46
+ formatQuery: this.formatQuery.bind(this),
47
+ dialect: __classPrivateFieldGet(this, _dialect),
48
+ });
49
+ }
50
+ async patchList(input) {
51
+ return __shared_1.patchList({
52
+ ...input,
53
+ dbCall: this.dbCall.bind(this),
54
+ formatQuery: this.formatQuery.bind(this),
55
+ dialect: __classPrivateFieldGet(this, _dialect),
56
+ });
57
+ }
58
+ async del(input) {
59
+ return __shared_1.del({
60
+ ...input,
61
+ dbCall: this.dbCall.bind(this),
62
+ formatQuery: this.formatQuery.bind(this),
63
+ dialect: __classPrivateFieldGet(this, _dialect),
64
+ });
65
+ }
66
+ async deleteList(input) {
67
+ return __shared_1.deleteList({
68
+ ...input,
69
+ dbCall: this.dbCall.bind(this),
70
+ formatQuery: this.formatQuery.bind(this),
71
+ dialect: __classPrivateFieldGet(this, _dialect),
72
+ });
73
+ }
74
+ whereNeedsProcessing(where) {
75
+ return __shared_1.whereNeedsProcessing(where);
76
+ }
77
+ async _prepareWhere(artifacts, table, data) {
78
+ return __shared_1._prepareWhere(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
79
+ }
80
+ async dbCall(q) {
81
+ return __classPrivateFieldGet(this, _mssqlClient).dbCall(q);
82
+ }
83
+ formatQuery(q, values) {
84
+ return __classPrivateFieldGet(this, _mssqlClient).formatQuery(q, values);
85
+ }
86
+ }
87
+ exports.RuntimeMSSQL = RuntimeMSSQL;
88
+ _dialect = new WeakMap(), _mssqlClient = new WeakMap();
@@ -0,0 +1,20 @@
1
+ import type { IRuntime, TResolveInput, TPatchInput, TPostInput, TPatchListInput, TDelInput, TDeleteListInput } from "./IRuntime";
2
+ import type { IArtifacts, ISupplementClientOpts } from "../types";
3
+ export declare class RuntimeMySQL implements IRuntime {
4
+ #private;
5
+ constructor(clientOpts: {
6
+ [k: string]: any;
7
+ }, otherOpts: {
8
+ supplementClientOpts?: ISupplementClientOpts;
9
+ }, artifacts: IArtifacts);
10
+ resolve(input: TResolveInput): Promise<any>;
11
+ post(input: TPostInput): Promise<any>;
12
+ patch(input: TPatchInput): Promise<any>;
13
+ patchList(input: TPatchListInput): Promise<any>;
14
+ del(input: TDelInput): Promise<boolean>;
15
+ deleteList(input: TDeleteListInput): Promise<boolean>;
16
+ whereNeedsProcessing(where: any): boolean;
17
+ _prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
18
+ private dbCall;
19
+ private formatQuery;
20
+ }
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to get private field on non-instance");
5
+ }
6
+ return privateMap.get(receiver);
7
+ };
8
+ var _dialect;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.RuntimeMySQL = void 0;
11
+ const SqlString = require("sqlstring");
12
+ const mysql_1 = require("../mysql");
13
+ const __shared_1 = require("./__shared");
14
+ class RuntimeMySQL {
15
+ constructor(clientOpts, otherOpts, artifacts) {
16
+ _dialect.set(this, "mysql");
17
+ if (otherOpts.supplementClientOpts) {
18
+ clientOpts = {
19
+ supportBigNumbers: true,
20
+ typeCast: (field, next) => {
21
+ if (field.type == "TINY" && field.length == 1) {
22
+ return field.string() == "1";
23
+ }
24
+ // if (field.type === "DATE") {
25
+ // return field.string();
26
+ // }
27
+ // if (
28
+ // field.type === "TIMESTAMP" ||
29
+ // field.type === "DATE" ||
30
+ // field.type === "DATETIME"
31
+ // ) {
32
+ // return new Date(field.string()).toISOString();
33
+ // }
34
+ if (field.type === "VAR_STRING" || field.type === "STRING") {
35
+ return field.string();
36
+ }
37
+ return next();
38
+ },
39
+ ...clientOpts,
40
+ };
41
+ }
42
+ else {
43
+ clientOpts = {
44
+ typeCast: (field, next) => {
45
+ if (field.type == "TINY" && field.length == 1) {
46
+ return field.string() == "1";
47
+ }
48
+ if (field.type === "VAR_STRING" || field.type === "STRING") {
49
+ return field.string();
50
+ }
51
+ return next();
52
+ },
53
+ ...clientOpts,
54
+ };
55
+ }
56
+ mysql_1.init(clientOpts);
57
+ }
58
+ async resolve(input) {
59
+ return __shared_1.resolve(input, this.dbCall.bind(this), this.formatQuery.bind(this), {
60
+ dialect: __classPrivateFieldGet(this, _dialect),
61
+ });
62
+ }
63
+ async post(input) {
64
+ return __shared_1.post({
65
+ ...input,
66
+ dbCall: this.dbCall.bind(this),
67
+ formatQuery: this.formatQuery.bind(this),
68
+ dialect: __classPrivateFieldGet(this, _dialect),
69
+ });
70
+ }
71
+ async patch(input) {
72
+ return __shared_1.patch({
73
+ ...input,
74
+ dbCall: this.dbCall.bind(this),
75
+ formatQuery: this.formatQuery.bind(this),
76
+ dialect: __classPrivateFieldGet(this, _dialect),
77
+ });
78
+ }
79
+ async patchList(input) {
80
+ return __shared_1.patchList({
81
+ ...input,
82
+ dbCall: this.dbCall.bind(this),
83
+ formatQuery: this.formatQuery.bind(this),
84
+ dialect: __classPrivateFieldGet(this, _dialect),
85
+ });
86
+ }
87
+ async del(input) {
88
+ return __shared_1.del({
89
+ ...input,
90
+ dbCall: this.dbCall.bind(this),
91
+ formatQuery: this.formatQuery.bind(this),
92
+ dialect: __classPrivateFieldGet(this, _dialect),
93
+ });
94
+ }
95
+ async deleteList(input) {
96
+ return __shared_1.deleteList({
97
+ ...input,
98
+ dbCall: this.dbCall.bind(this),
99
+ formatQuery: this.formatQuery.bind(this),
100
+ dialect: __classPrivateFieldGet(this, _dialect),
101
+ });
102
+ }
103
+ whereNeedsProcessing(where) {
104
+ return __shared_1.whereNeedsProcessing(where);
105
+ }
106
+ async _prepareWhere(artifacts, table, data) {
107
+ return __shared_1._prepareWhere(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
108
+ }
109
+ dbCall(q) {
110
+ return mysql_1.query(q);
111
+ }
112
+ formatQuery(q, values) {
113
+ return SqlString.format(q, values);
114
+ }
115
+ }
116
+ exports.RuntimeMySQL = RuntimeMySQL;
117
+ _dialect = new WeakMap();
@@ -0,0 +1,7 @@
1
+ import * as mssql from "mssql";
2
+ export declare class MSSQL {
3
+ #private;
4
+ constructor(clientOpts: mssql.config, typeCast?: Function);
5
+ dbCall(q: string): Promise<any>;
6
+ formatQuery(q: string, values: any[]): any;
7
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to set private field on non-instance");
5
+ }
6
+ privateMap.set(receiver, value);
7
+ return value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to get private field on non-instance");
12
+ }
13
+ return privateMap.get(receiver);
14
+ };
15
+ var _pool, _poolConnect, _typeCast;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.MSSQL = void 0;
18
+ const mssql = require("mssql");
19
+ // @ts-ignore
20
+ const TSqlString = require("tsqlstring");
21
+ class MSSQL {
22
+ constructor(clientOpts, typeCast) {
23
+ _pool.set(this, void 0);
24
+ _poolConnect.set(this, void 0);
25
+ _typeCast.set(this, void 0);
26
+ __classPrivateFieldSet(this, _typeCast, typeCast);
27
+ __classPrivateFieldSet(this, _pool, new mssql.ConnectionPool(clientOpts));
28
+ __classPrivateFieldSet(this, _poolConnect, __classPrivateFieldGet(this, _pool).connect());
29
+ }
30
+ async dbCall(q) {
31
+ await __classPrivateFieldGet(this, _poolConnect);
32
+ const request = __classPrivateFieldGet(this, _pool).request();
33
+ const result = await request.query(q);
34
+ // TODO: see https://github.com/tediousjs/node-mssql/pull/1171
35
+ const meta = result.recordset?.columns;
36
+ if (meta != null && typeof __classPrivateFieldGet(this, _typeCast) === "function") {
37
+ return __classPrivateFieldGet(this, _typeCast).call(this, result, meta);
38
+ }
39
+ return result.recordset;
40
+ }
41
+ formatQuery(q, values) {
42
+ return TSqlString.format(q, values);
43
+ }
44
+ }
45
+ exports.MSSQL = MSSQL;
46
+ _pool = new WeakMap(), _poolConnect = new WeakMap(), _typeCast = new WeakMap();
@@ -0,0 +1,32 @@
1
+ import type { IArtifacts, IDialect, TDbCall, TFormatQuery } from "../types";
2
+ import { TResolveInput, TPatchInput, TPatchListInput, TPostInput, TDelInput, TDeleteListInput } from "./IRuntime";
3
+ export declare function resolve(input: TResolveInput, dbCall: TDbCall, formatQuery: TFormatQuery, options: {
4
+ dialect: IDialect;
5
+ }): Promise<any>;
6
+ export declare function post(input: TPostInput & {
7
+ dialect: IDialect;
8
+ dbCall: TDbCall;
9
+ formatQuery: TFormatQuery;
10
+ }): Promise<any>;
11
+ export declare function patch(input: TPatchInput & {
12
+ dialect: IDialect;
13
+ dbCall: TDbCall;
14
+ formatQuery: TFormatQuery;
15
+ }): Promise<any>;
16
+ export declare function patchList(input: TPatchListInput & {
17
+ dialect: IDialect;
18
+ dbCall: TDbCall;
19
+ formatQuery: TFormatQuery;
20
+ }): Promise<any>;
21
+ export declare function del(input: TDelInput & {
22
+ dialect: IDialect;
23
+ dbCall: TDbCall;
24
+ formatQuery: TFormatQuery;
25
+ }): Promise<boolean>;
26
+ export declare function deleteList(input: TDeleteListInput & {
27
+ dialect: IDialect;
28
+ dbCall: TDbCall;
29
+ formatQuery: TFormatQuery;
30
+ }): Promise<boolean>;
31
+ export declare function whereNeedsProcessing(where: any): boolean;
32
+ export declare function _prepareWhere(artifacts: IArtifacts, table: string, data: any, dbCall: TDbCall, formatQuery: TFormatQuery): Promise<{}>;