@sqb/connect 4.17.0 → 4.18.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.
@@ -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
  /**
@@ -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.18.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",
@@ -17,10 +17,10 @@
17
17
  "putil-varhelpers": "^1.6.5",
18
18
  "strict-typed-events": "^2.8.0",
19
19
  "ts-gems": "^3.5.0",
20
- "tslib": "^2.6.3"
20
+ "tslib": "^2.7.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "@sqb/builder": "^4.17.0",
23
+ "@sqb/builder": "^4.18.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
  *