@technicity/data-service-generator 0.6.1 → 0.7.3

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.
@@ -15,7 +15,7 @@ const TSqlString = require("tsqlstring");
15
15
  const json_schema_to_typescript_1 = require("json-schema-to-typescript");
16
16
  const getDuplicates_1 = require("../lib/getDuplicates");
17
17
  const isNotNullOrUndefined_1 = require("../lib/isNotNullOrUndefined");
18
- const mysql = require("../mysql");
18
+ const MySQL_1 = require("../runtime/lib/MySQL");
19
19
  // json-schema-to-typescript inlines everything. We don't want that,
20
20
  // so use `tsType`, and add imports manually.
21
21
  // https://github.com/bcherny/json-schema-to-typescript#custom-schema-properties
@@ -138,14 +138,14 @@ exports.generate = generate;
138
138
  function init(input) {
139
139
  const { database, user, password, host, port, server } = input;
140
140
  if (dialect === "mysql") {
141
- mysql.init({
141
+ let mysql = new MySQL_1.MySQL({
142
142
  user,
143
143
  password,
144
144
  host,
145
145
  port,
146
146
  database,
147
147
  });
148
- query = mysql.query;
148
+ query = mysql.query.bind(mysql);
149
149
  }
150
150
  if (dialect === "mssql" || dialect === "ksql") {
151
151
  const pool = new mssql.ConnectionPool({
@@ -1240,7 +1240,7 @@ const getRelationsOneToMany = _.memoize(async function getRelationsOneToMany(tab
1240
1240
  nullable: false,
1241
1241
  };
1242
1242
  })));
1243
- return _.sortBy((x) => x.referencedTable, xs);
1243
+ return _.sortBy((x) => x.referencedKey, _.sortBy((x) => x.referencedTable, xs));
1244
1244
  });
1245
1245
  async function getPrimaryColumn(table) {
1246
1246
  const tableMeta = await getTableMeta(table);
@@ -10,15 +10,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _RuntimeMySQL_dialect, _RuntimeMySQL_middlewareHandler;
13
+ var _RuntimeMySQL_dialect, _RuntimeMySQL_mysqlClient, _RuntimeMySQL_middlewareHandler;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.RuntimeMySQL = void 0;
16
16
  const SqlString = require("sqlstring");
17
- const mysql_1 = require("../mysql");
17
+ const MySQL_1 = require("./lib/MySQL");
18
18
  const shared_1 = require("./lib/shared");
19
19
  class RuntimeMySQL {
20
20
  constructor(clientOpts, otherOpts, artifacts) {
21
21
  _RuntimeMySQL_dialect.set(this, "mysql");
22
+ _RuntimeMySQL_mysqlClient.set(this, void 0);
22
23
  _RuntimeMySQL_middlewareHandler.set(this, void 0);
23
24
  __classPrivateFieldSet(this, _RuntimeMySQL_middlewareHandler, new shared_1.MiddlewareHandler(), "f");
24
25
  if (otherOpts.supplementClientOpts) {
@@ -60,7 +61,7 @@ class RuntimeMySQL {
60
61
  ...clientOpts,
61
62
  };
62
63
  }
63
- (0, mysql_1.init)(clientOpts);
64
+ __classPrivateFieldSet(this, _RuntimeMySQL_mysqlClient, new MySQL_1.MySQL(clientOpts), "f");
64
65
  }
65
66
  async resolve(input) {
66
67
  return (0, shared_1.resolve)(input, this.dbCall.bind(this), this.formatQuery.bind(this), this.beginTransaction.bind(this), __classPrivateFieldGet(this, _RuntimeMySQL_dialect, "f"), __classPrivateFieldGet(this, _RuntimeMySQL_middlewareHandler, "f"), input.context ?? {});
@@ -78,14 +79,14 @@ class RuntimeMySQL {
78
79
  return (0, shared_1._prepareWhere)(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
79
80
  }
80
81
  dbCall(q) {
81
- return (0, mysql_1.query)(q);
82
+ return __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").query(q);
82
83
  }
83
84
  formatQuery(q, values) {
84
85
  return SqlString.format(q, values);
85
86
  }
86
87
  beginTransaction() {
87
- return (0, mysql_1.beginTransaction)();
88
+ return __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").beginTransaction();
88
89
  }
89
90
  }
90
91
  exports.RuntimeMySQL = RuntimeMySQL;
91
- _RuntimeMySQL_dialect = new WeakMap(), _RuntimeMySQL_middlewareHandler = new WeakMap();
92
+ _RuntimeMySQL_dialect = new WeakMap(), _RuntimeMySQL_mysqlClient = new WeakMap(), _RuntimeMySQL_middlewareHandler = new WeakMap();
@@ -0,0 +1,7 @@
1
+ export declare class MySQL {
2
+ pool: any;
3
+ constructor(opts: any);
4
+ query(...args: any[]): any;
5
+ beginTransaction(): Promise<any>;
6
+ getConnection(): Promise<any>;
7
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MySQL = void 0;
4
+ const mysql = require("mysql");
5
+ const P = require("bluebird");
6
+ P.promisifyAll(require("mysql/lib/Connection").prototype);
7
+ P.promisifyAll(require("mysql/lib/Pool").prototype);
8
+ class MySQL {
9
+ constructor(opts) {
10
+ this.pool = mysql.createPool(opts);
11
+ }
12
+ // http://bluebirdjs.com/docs/api/promise.using.html
13
+ query(...args) {
14
+ return P.using(this.getConnection(), (connection) => connection.queryAsync(...args));
15
+ }
16
+ async beginTransaction() {
17
+ return P.using(this.getConnection(), async (connection) => {
18
+ async function handleError(err) {
19
+ await connection.rollbackAsync();
20
+ throw err;
21
+ }
22
+ await connection.beginTransactionAsync();
23
+ return {
24
+ commit: () => connection.commitAsync().catch(handleError),
25
+ dbCall: (q) => connection.queryAsync(q).catch(handleError),
26
+ };
27
+ });
28
+ }
29
+ // http://bluebirdjs.com/docs/api/disposer.html
30
+ async getConnection() {
31
+ return this.pool
32
+ .getConnectionAsync()
33
+ .disposer((connection) => connection.release());
34
+ }
35
+ }
36
+ exports.MySQL = MySQL;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.6.1",
3
+ "version": "0.7.3",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
8
8
  "scripts": {
9
9
  "compile": "rm -rf dist && tsc",
10
- "create-database": "env-cmd node ./test/mysql/create-database.js && env-cmd node ./test/mssql/create-database.js",
11
- "generate": "npm run compile && npm run create-database && env-cmd node ./test/mysql/generate.js && env-cmd node ./test/mssql/generate.js",
10
+ "create-database": "env-cmd node ./test/mysql/create-database.js && env-cmd node ./test/mysql8/create-database.js && env-cmd node ./test/mssql/create-database.js",
11
+ "generate": "npm run compile && npm run create-database && env-cmd node ./test/mysql/generate.js && env-cmd node ./test/mysql8/generate.js && env-cmd node ./test/mssql/generate.js",
12
12
  "test": "npm run generate && env-cmd mocha ./test/addNullFallbacks.test.js && env-cmd mocha ./test/stringifyWhere.test.js && env-cmd mocha ./test/test.js"
13
13
  },
14
14
  "dependencies": {
@@ -17,7 +17,7 @@
17
17
  "fs-extra": "10.0.0",
18
18
  "graphql": "15.8.0",
19
19
  "graphql-relay": "^0.9.0",
20
- "join-monster": "apalm/join-monster#340bcad96da4c268e874d07552d564c98ecf39ea",
20
+ "join-monster": "git+https://github.com/apalm/join-monster.git#340bcad96da4c268e874d07552d564c98ecf39ea",
21
21
  "json-schema-to-typescript": "10.1.5",
22
22
  "lodash": "^4.17.20",
23
23
  "mssql": "^6.3.1",
package/dist/mysql.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export function init(opts: any): void;
2
- export function query(...args: any[]): any;
3
- export function beginTransaction(): Promise<any>;
package/dist/mysql.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- const mysql = require("mysql");
3
- const Promise = require("bluebird");
4
- Promise.promisifyAll(require("mysql/lib/Connection").prototype);
5
- Promise.promisifyAll(require("mysql/lib/Pool").prototype);
6
- let pool;
7
- function init(opts) {
8
- pool = mysql.createPool(opts);
9
- }
10
- // http://bluebirdjs.com/docs/api/disposer.html
11
- async function getConnection() {
12
- return pool
13
- .getConnectionAsync()
14
- .disposer((connection) => connection.release());
15
- }
16
- // http://bluebirdjs.com/docs/api/promise.using.html
17
- function query(...args) {
18
- return Promise.using(getConnection(), (connection) => connection.queryAsync(...args));
19
- }
20
- async function beginTransaction() {
21
- return Promise.using(getConnection(), async (connection) => {
22
- async function handleError(err) {
23
- await connection.rollbackAsync();
24
- throw err;
25
- }
26
- await connection.beginTransactionAsync();
27
- return {
28
- commit: () => connection.commitAsync().catch(handleError),
29
- dbCall: (q) => connection.queryAsync(q).catch(handleError),
30
- };
31
- });
32
- }
33
- module.exports.init = init;
34
- module.exports.query = query;
35
- module.exports.beginTransaction = beginTransaction;