@sqb/connect 4.17.0 → 4.19.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.
@@ -62,7 +62,7 @@ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
62
62
  else
63
63
  srcOp.add(filter);
64
64
  }
65
- const associationPathCache = {};
65
+ // const associationPathCache: Record<string, any> = {};
66
66
  for (const item of srcOp._items) {
67
67
  if ((0, builder_1.isLogicalOperator)(item)) {
68
68
  const ctor = Object.getPrototypeOf(item).constructor;
@@ -83,18 +83,18 @@ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
83
83
  let subSelect;
84
84
  let currentOp = trgOp;
85
85
  let i = 0;
86
- const parentPath = itemPath
87
- .slice(0, l - 2)
88
- .join('.')
89
- .toLowerCase();
90
- const cached = associationPathCache[parentPath];
91
- if (cached) {
92
- /** Jump to last item */
93
- i = l - 1;
94
- _curEntity = cached._curEntity;
95
- _curAlias = cached._curAlias;
96
- currentOp = cached.currentOp;
97
- }
86
+ // const parentPath = itemPath
87
+ // .slice(0, l - 2)
88
+ // .join('.')
89
+ // .toLowerCase();
90
+ // const cached = associationPathCache[parentPath];
91
+ // if (cached) {
92
+ // /** Jump to last item */
93
+ // i = l - 1;
94
+ // _curEntity = cached._curEntity;
95
+ // _curAlias = cached._curAlias;
96
+ // currentOp = cached.currentOp;
97
+ // }
98
98
  for (i; i < l; i++) {
99
99
  pt = itemPath[i];
100
100
  const col = entity_metadata_js_1.EntityMetadata.getField(_curEntity, pt);
@@ -151,14 +151,14 @@ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
151
151
  _curAlias = joinAlias;
152
152
  node = node.next;
153
153
  }
154
- /** If next path is the last one */
155
- if (i === l - 2) {
156
- associationPathCache[parentPath] = {
157
- _curEntity,
158
- _curAlias,
159
- currentOp,
160
- };
161
- }
154
+ // /** If next path is the last one */
155
+ // if (i === l - 2) {
156
+ // associationPathCache[parentPath] = {
157
+ // _curEntity,
158
+ // _curAlias,
159
+ // currentOp,
160
+ // };
161
+ // }
162
162
  }
163
163
  }
164
164
  continue;
@@ -8,6 +8,7 @@ const create_command_js_1 = require("./commands/create.command.js");
8
8
  const delete_command_js_1 = require("./commands/delete.command.js");
9
9
  const find_command_js_1 = require("./commands/find.command.js");
10
10
  const update_command_js_1 = require("./commands/update.command.js");
11
+ const entity_metadata_js_1 = require("./model/entity-metadata.js");
11
12
  const extract_keyvalues_js_1 = require("./util/extract-keyvalues.js");
12
13
  /**
13
14
  * @class Repository
@@ -40,11 +41,16 @@ class Repository extends (0, strict_typed_events_1.TypedEventEmitterClass)(stric
40
41
  *
41
42
  * @param {PartialDTO<T>} input - The input data
42
43
  * @param {Repository.CreateOptions} [options] - The options object
44
+ * @returns {Promise<any>} A promise that resolves key value(s) of the created record
43
45
  * @throws {Error} if an unknown error occurs while creating the resource
44
46
  */
45
47
  createOnly(input, options) {
46
48
  return this._execute(async (connection) => {
47
- await this._create(input, { ...options, connection, returning: false });
49
+ const r = await this._create(input, { ...options, connection, returning: true });
50
+ const primaryIndex = entity_metadata_js_1.EntityMetadata.getPrimaryIndex(this.entity);
51
+ if (!primaryIndex || primaryIndex.columns.length > 1)
52
+ return r;
53
+ return r[primaryIndex.columns[0]];
48
54
  }, options);
49
55
  }
50
56
  /**
@@ -56,7 +56,7 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
56
56
  else
57
57
  srcOp.add(filter);
58
58
  }
59
- const associationPathCache = {};
59
+ // const associationPathCache: Record<string, any> = {};
60
60
  for (const item of srcOp._items) {
61
61
  if (isLogicalOperator(item)) {
62
62
  const ctor = Object.getPrototypeOf(item).constructor;
@@ -77,18 +77,18 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
77
77
  let subSelect;
78
78
  let currentOp = trgOp;
79
79
  let i = 0;
80
- const parentPath = itemPath
81
- .slice(0, l - 2)
82
- .join('.')
83
- .toLowerCase();
84
- const cached = associationPathCache[parentPath];
85
- if (cached) {
86
- /** Jump to last item */
87
- i = l - 1;
88
- _curEntity = cached._curEntity;
89
- _curAlias = cached._curAlias;
90
- currentOp = cached.currentOp;
91
- }
80
+ // const parentPath = itemPath
81
+ // .slice(0, l - 2)
82
+ // .join('.')
83
+ // .toLowerCase();
84
+ // const cached = associationPathCache[parentPath];
85
+ // if (cached) {
86
+ // /** Jump to last item */
87
+ // i = l - 1;
88
+ // _curEntity = cached._curEntity;
89
+ // _curAlias = cached._curAlias;
90
+ // currentOp = cached.currentOp;
91
+ // }
92
92
  for (i; i < l; i++) {
93
93
  pt = itemPath[i];
94
94
  const col = EntityMetadata.getField(_curEntity, pt);
@@ -145,14 +145,14 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
145
145
  _curAlias = joinAlias;
146
146
  node = node.next;
147
147
  }
148
- /** If next path is the last one */
149
- if (i === l - 2) {
150
- associationPathCache[parentPath] = {
151
- _curEntity,
152
- _curAlias,
153
- currentOp,
154
- };
155
- }
148
+ // /** If next path is the last one */
149
+ // if (i === l - 2) {
150
+ // associationPathCache[parentPath] = {
151
+ // _curEntity,
152
+ // _curAlias,
153
+ // currentOp,
154
+ // };
155
+ // }
156
156
  }
157
157
  }
158
158
  continue;
@@ -5,6 +5,7 @@ import { CreateCommand } from './commands/create.command.js';
5
5
  import { DeleteCommand } from './commands/delete.command.js';
6
6
  import { FindCommand } from './commands/find.command.js';
7
7
  import { UpdateCommand } from './commands/update.command.js';
8
+ import { EntityMetadata } from './model/entity-metadata.js';
8
9
  import { extractKeyValues } from './util/extract-keyvalues.js';
9
10
  /**
10
11
  * @class Repository
@@ -37,11 +38,16 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
37
38
  *
38
39
  * @param {PartialDTO<T>} input - The input data
39
40
  * @param {Repository.CreateOptions} [options] - The options object
41
+ * @returns {Promise<any>} A promise that resolves key value(s) of the created record
40
42
  * @throws {Error} if an unknown error occurs while creating the resource
41
43
  */
42
44
  createOnly(input, options) {
43
45
  return this._execute(async (connection) => {
44
- await this._create(input, { ...options, connection, returning: false });
46
+ const r = await this._create(input, { ...options, connection, returning: true });
47
+ const primaryIndex = EntityMetadata.getPrimaryIndex(this.entity);
48
+ if (!primaryIndex || primaryIndex.columns.length > 1)
49
+ return r;
50
+ return r[primaryIndex.columns[0]];
45
51
  }, options);
46
52
  }
47
53
  /**
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@sqb/connect",
3
3
  "description": "Multi-dialect database connection framework written with TypeScript",
4
- "version": "4.17.0",
4
+ "version": "4.19.0",
5
5
  "author": "Panates",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
8
- "debug": "^4.3.6",
8
+ "debug": "^4.3.7",
9
9
  "doublylinked": "^2.5.4",
10
10
  "fast-tokenizer": "^1.7.0",
11
11
  "lightning-pool": "^4.8.0",
@@ -16,11 +16,11 @@
16
16
  "putil-promisify": "^1.10.1",
17
17
  "putil-varhelpers": "^1.6.5",
18
18
  "strict-typed-events": "^2.8.0",
19
- "ts-gems": "^3.5.0",
20
- "tslib": "^2.6.3"
19
+ "ts-gems": "^3.5.1",
20
+ "tslib": "^2.7.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "@sqb/builder": "^4.17.0",
23
+ "@sqb/builder": "^4.19.0",
24
24
  "reflect-metadata": "^0.2.2"
25
25
  },
26
26
  "type": "module",
@@ -80,9 +80,10 @@ export declare class Repository<T> extends Repository_base {
80
80
  *
81
81
  * @param {PartialDTO<T>} input - The input data
82
82
  * @param {Repository.CreateOptions} [options] - The options object
83
+ * @returns {Promise<any>} A promise that resolves key value(s) of the created record
83
84
  * @throws {Error} if an unknown error occurs while creating the resource
84
85
  */
85
- createOnly(input: PartialDTO<T>, options?: StrictOmit<Repository.CreateOptions, keyof Projection>): Promise<void>;
86
+ createOnly(input: PartialDTO<T>, options?: StrictOmit<Repository.CreateOptions, keyof Projection>): Promise<any>;
86
87
  /**
87
88
  * Returns the count of records based on the provided options
88
89
  *