@sqb/connect 4.8.0 → 4.9.0

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.
@@ -4,7 +4,7 @@ exports.Cursor = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const debug_1 = tslib_1.__importDefault(require("debug"));
6
6
  const doublylinked_1 = tslib_1.__importDefault(require("doublylinked"));
7
- const putil_taskqueue_1 = tslib_1.__importDefault(require("putil-taskqueue"));
7
+ const power_tasks_1 = require("power-tasks");
8
8
  const putil_varhelpers_1 = require("putil-varhelpers");
9
9
  const strict_typed_events_1 = require("strict-typed-events");
10
10
  const cursor_stream_js_1 = require("./cursor-stream.js");
@@ -16,7 +16,7 @@ class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_ty
16
16
  _prefetchRows;
17
17
  _request;
18
18
  _intlcur;
19
- _taskQueue = new putil_taskqueue_1.default();
19
+ _taskQueue = new power_tasks_1.TaskQueue();
20
20
  _fetchCache = new doublylinked_1.default();
21
21
  _rowNum = 0;
22
22
  _fetchedAll = false;
@@ -219,7 +219,7 @@ class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_ty
219
219
  return;
220
220
  await _this._fetchRows();
221
221
  }
222
- });
222
+ }).toPromise();
223
223
  if (!silent)
224
224
  this.emit('move', this.row, this._rowNum);
225
225
  return this._rowNum;
@@ -4,7 +4,7 @@ exports.SqbConnection = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const assert_1 = tslib_1.__importDefault(require("assert"));
6
6
  const debug_1 = tslib_1.__importDefault(require("debug"));
7
- const putil_taskqueue_1 = tslib_1.__importDefault(require("putil-taskqueue"));
7
+ const power_tasks_1 = require("power-tasks");
8
8
  const putil_varhelpers_1 = require("putil-varhelpers");
9
9
  const strict_typed_events_1 = require("strict-typed-events");
10
10
  const builder_1 = require("@sqb/builder");
@@ -16,7 +16,7 @@ const debug = (0, debug_1.default)('sqb:connection');
16
16
  class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
17
17
  client;
18
18
  _intlcon;
19
- _tasks = new putil_taskqueue_1.default();
19
+ _tasks = new power_tasks_1.TaskQueue();
20
20
  _options;
21
21
  _inTransaction = false;
22
22
  _refCount = 1;
@@ -90,7 +90,7 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
90
90
  async execute(query, options) {
91
91
  if (!this._intlcon)
92
92
  throw new Error(`Can't execute query, because connection is released`);
93
- return this._tasks.enqueue(() => this._execute(query, options));
93
+ return this._tasks.enqueue(() => this._execute(query, options)).toPromise();
94
94
  }
95
95
  getRepository(entity, opts) {
96
96
  let ctor;
@@ -264,9 +264,11 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
264
264
  if (query.listenerCount('fetch'))
265
265
  request.fetchHooks = query.listeners('fetch');
266
266
  }
267
- else if (typeof query === 'string') {
268
- request.sql = query;
269
- request.params = options.params;
267
+ else { // noinspection SuspiciousTypeOfGuard
268
+ if (typeof query === 'string') {
269
+ request.sql = query;
270
+ request.params = options.params;
271
+ }
270
272
  }
271
273
  // @ts-ignore
272
274
  if (!request.sql)
@@ -81,19 +81,19 @@ class Repository extends (0, strict_typed_events_1.TypedEventEmitterClass)(stric
81
81
  update(keyValue, values, options) {
82
82
  return this._execute(async (connection) => {
83
83
  const opts = { ...options, connection };
84
- const keyValues = await this._updateByPk(keyValue, values, opts);
84
+ const keyValues = await this._update(keyValue, values, opts);
85
85
  if (keyValues)
86
86
  return this._find(keyValues, opts);
87
87
  }, options);
88
88
  }
89
89
  updateOnly(keyValue, values, options) {
90
90
  return this._execute(async (connection) => {
91
- return !!(await this._updateByPk(keyValue, values, { ...options, connection }));
91
+ return !!(await this._update(keyValue, values, { ...options, connection }));
92
92
  }, options);
93
93
  }
94
94
  updateMany(values, options) {
95
95
  return this._execute(async (connection) => {
96
- return this._updateAll(values, { ...options, connection });
96
+ return this._updateMany(values, { ...options, connection });
97
97
  });
98
98
  }
99
99
  /**
@@ -217,7 +217,7 @@ class Repository extends (0, strict_typed_events_1.TypedEventEmitterClass)(stric
217
217
  params: options?.params
218
218
  });
219
219
  }
220
- async _updateByPk(keyValue, values, options) {
220
+ async _update(keyValue, values, options) {
221
221
  if (!values)
222
222
  throw new TypeError('You must provide values');
223
223
  const keyValues = (0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true);
@@ -238,7 +238,7 @@ class Repository extends (0, strict_typed_events_1.TypedEventEmitterClass)(stric
238
238
  });
239
239
  return rowsAffected ? keyValues : undefined;
240
240
  }
241
- async _updateAll(values, options) {
241
+ async _updateMany(values, options) {
242
242
  if (!values)
243
243
  throw new TypeError('You must provide values');
244
244
  return await update_command_js_1.UpdateCommand.execute({
@@ -1,6 +1,6 @@
1
1
  import _debug from 'debug';
2
2
  import DoublyLinked from 'doublylinked';
3
- import TaskQueue from 'putil-taskqueue';
3
+ import { TaskQueue } from 'power-tasks';
4
4
  import { coerceToInt } from 'putil-varhelpers';
5
5
  import { AsyncEventEmitter, TypedEventEmitterClass } from 'strict-typed-events';
6
6
  import { CursorStream } from './cursor-stream.js';
@@ -215,7 +215,7 @@ export class Cursor extends TypedEventEmitterClass(AsyncEventEmitter) {
215
215
  return;
216
216
  await _this._fetchRows();
217
217
  }
218
- });
218
+ }).toPromise();
219
219
  if (!silent)
220
220
  this.emit('move', this.row, this._rowNum);
221
221
  return this._rowNum;
@@ -1,6 +1,6 @@
1
1
  import assert from 'assert';
2
2
  import _debug from 'debug';
3
- import TaskQueue from 'putil-taskqueue';
3
+ import { TaskQueue } from 'power-tasks';
4
4
  import { coalesce, coerceToBoolean, coerceToInt, coerceToString } from "putil-varhelpers";
5
5
  import { AsyncEventEmitter, TypedEventEmitterClass } from 'strict-typed-events';
6
6
  import { classes } from '@sqb/builder';
@@ -86,7 +86,7 @@ export class SqbConnection extends TypedEventEmitterClass(AsyncEventEmitter) {
86
86
  async execute(query, options) {
87
87
  if (!this._intlcon)
88
88
  throw new Error(`Can't execute query, because connection is released`);
89
- return this._tasks.enqueue(() => this._execute(query, options));
89
+ return this._tasks.enqueue(() => this._execute(query, options)).toPromise();
90
90
  }
91
91
  getRepository(entity, opts) {
92
92
  let ctor;
@@ -260,9 +260,11 @@ export class SqbConnection extends TypedEventEmitterClass(AsyncEventEmitter) {
260
260
  if (query.listenerCount('fetch'))
261
261
  request.fetchHooks = query.listeners('fetch');
262
262
  }
263
- else if (typeof query === 'string') {
264
- request.sql = query;
265
- request.params = options.params;
263
+ else { // noinspection SuspiciousTypeOfGuard
264
+ if (typeof query === 'string') {
265
+ request.sql = query;
266
+ request.params = options.params;
267
+ }
266
268
  }
267
269
  // @ts-ignore
268
270
  if (!request.sql)
@@ -130,10 +130,10 @@ export declare class Repository<T> extends Repository_base {
130
130
  protected _deleteMany(options: Repository.DeleteManyOptions & {
131
131
  connection: SqbConnection;
132
132
  }): Promise<number>;
133
- protected _updateByPk(keyValue: any | Record<string, any>, values: EntityInput<T>, options: Repository.UpdateOptions & {
133
+ protected _update(keyValue: any | Record<string, any>, values: EntityInput<T>, options: Repository.UpdateOptions & {
134
134
  connection: SqbConnection;
135
135
  }): Promise<Record<string, any> | undefined>;
136
- protected _updateAll(values: EntityInput<T>, options: Repository.UpdateManyOptions & {
136
+ protected _updateMany(values: EntityInput<T>, options: Repository.UpdateManyOptions & {
137
137
  connection: SqbConnection;
138
138
  }): Promise<number>;
139
139
  }
@@ -78,19 +78,19 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
78
78
  update(keyValue, values, options) {
79
79
  return this._execute(async (connection) => {
80
80
  const opts = { ...options, connection };
81
- const keyValues = await this._updateByPk(keyValue, values, opts);
81
+ const keyValues = await this._update(keyValue, values, opts);
82
82
  if (keyValues)
83
83
  return this._find(keyValues, opts);
84
84
  }, options);
85
85
  }
86
86
  updateOnly(keyValue, values, options) {
87
87
  return this._execute(async (connection) => {
88
- return !!(await this._updateByPk(keyValue, values, { ...options, connection }));
88
+ return !!(await this._update(keyValue, values, { ...options, connection }));
89
89
  }, options);
90
90
  }
91
91
  updateMany(values, options) {
92
92
  return this._execute(async (connection) => {
93
- return this._updateAll(values, { ...options, connection });
93
+ return this._updateMany(values, { ...options, connection });
94
94
  });
95
95
  }
96
96
  /**
@@ -214,7 +214,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
214
214
  params: options?.params
215
215
  });
216
216
  }
217
- async _updateByPk(keyValue, values, options) {
217
+ async _update(keyValue, values, options) {
218
218
  if (!values)
219
219
  throw new TypeError('You must provide values');
220
220
  const keyValues = extractKeyValues(this._entity, keyValue, true);
@@ -235,7 +235,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
235
235
  });
236
236
  return rowsAffected ? keyValues : undefined;
237
237
  }
238
- async _updateAll(values, options) {
238
+ async _updateMany(values, options) {
239
239
  if (!values)
240
240
  throw new TypeError('You must provide values');
241
241
  return await UpdateCommand.execute({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/connect",
3
3
  "description": "Multi-dialect database connection framework written with TypeScript",
4
- "version": "4.8.0",
4
+ "version": "4.9.0",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>",
@@ -32,10 +32,10 @@
32
32
  "debug": "^4.3.4",
33
33
  "lightning-pool": "^4.2.1",
34
34
  "lodash": "^4.17.21",
35
+ "power-tasks": "^1.6.4",
35
36
  "putil-isplainobject": "^1.1.5",
36
37
  "putil-merge": "^3.10.3",
37
38
  "putil-promisify": "^1.10.0",
38
- "putil-taskqueue": "^2.5.5",
39
39
  "putil-varhelpers": "^1.6.5",
40
40
  "reflect-metadata": "^0.1.13",
41
41
  "strict-typed-events": "^2.3.1",
@@ -46,7 +46,7 @@
46
46
  "@types/lodash": "^4.14.194"
47
47
  },
48
48
  "peerDependencies": {
49
- "@sqb/builder": "^4.8.0"
49
+ "@sqb/builder": "^4.9.0"
50
50
  },
51
51
  "type": "module",
52
52
  "types": "esm/index.d.ts",