@itrocks/mysql 0.0.16 → 0.0.17

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 (3) hide show
  1. package/cjs/mysql.js +12 -14
  2. package/esm/mysql.js +12 -14
  3. package/package.json +1 -1
package/cjs/mysql.js CHANGED
@@ -214,28 +214,26 @@ class Mysql extends storage_1.DataSource {
214
214
  const objectTable = depends.storeOf(object);
215
215
  const propertyType = new reflect_2.ReflectProperty(object, property).collectionType.elementType.type;
216
216
  const propertyTable = depends.storeOf(propertyType);
217
- const linkColumn = depends.columnOf(propertyTable + 'Id');
217
+ const linkColumn = depends.columnOf(propertyTable) + '_id';
218
218
  const linkTable = joinTableName(objectTable, propertyTable);
219
- const objectColumn = depends.columnOf(objectTable + 'Id');
219
+ const objectColumn = depends.columnOf(objectTable) + '_id';
220
220
  const objectId = object.id;
221
221
  const stored = await this.readCollectionIds(object, property, propertyType);
222
222
  const saved = [];
223
- const isLinkBigInt = typeof links[0] === 'bigint';
224
- const isStoredBigInt = typeof stored[0] === 'bigint';
225
- const isSameType = isLinkBigInt === isStoredBigInt;
226
- for (let link of links) {
223
+ for (const link of links) {
227
224
  const linkId = (typeof link === 'object')
228
- ? (link = this.isObjectConnected(link) ? link.id : (await this.save(link)).id)
225
+ ? (this.isObjectConnected(link) ? link.id : (await this.save(link)).id)
229
226
  : link;
230
- if (!stored.includes(isSameType ? linkId : (isStoredBigInt ? BigInt(linkId) : Number(linkId)))) {
231
- await connection.query('INSERT INTO `' + linkTable + '` SET ' + objectColumn + ' = ?, ' + linkColumn + ' = ?', [objectId, linkId]);
232
- }
233
227
  saved.push(linkId);
228
+ if (stored.includes(linkId))
229
+ continue;
230
+ await connection.query('INSERT INTO `' + linkTable + '` SET ' + objectColumn + ' = ?, ' + linkColumn + ' = ?', [objectId, linkId]);
231
+ stored.push(linkId);
234
232
  }
235
- for (let storedId of stored) {
236
- if (!saved.includes(isSameType ? storedId : (isLinkBigInt ? BigInt(storedId) : Number(storedId)))) {
237
- await connection.query('DELETE FROM `' + linkTable + '` WHERE ' + objectColumn + ' = ? AND ' + linkColumn + ' = ?', [objectId, storedId]);
238
- }
233
+ for (const storedId of stored) {
234
+ if (saved.includes(storedId))
235
+ continue;
236
+ await connection.query('DELETE FROM `' + linkTable + '` WHERE ' + objectColumn + ' = ? AND ' + linkColumn + ' = ?', [objectId, storedId]);
239
237
  }
240
238
  }
241
239
  async search(type, search = {}) {
package/esm/mysql.js CHANGED
@@ -209,28 +209,26 @@ export class Mysql extends DataSource {
209
209
  const objectTable = depends.storeOf(object);
210
210
  const propertyType = new ReflectProperty(object, property).collectionType.elementType.type;
211
211
  const propertyTable = depends.storeOf(propertyType);
212
- const linkColumn = depends.columnOf(propertyTable + 'Id');
212
+ const linkColumn = depends.columnOf(propertyTable) + '_id';
213
213
  const linkTable = joinTableName(objectTable, propertyTable);
214
- const objectColumn = depends.columnOf(objectTable + 'Id');
214
+ const objectColumn = depends.columnOf(objectTable) + '_id';
215
215
  const objectId = object.id;
216
216
  const stored = await this.readCollectionIds(object, property, propertyType);
217
217
  const saved = [];
218
- const isLinkBigInt = typeof links[0] === 'bigint';
219
- const isStoredBigInt = typeof stored[0] === 'bigint';
220
- const isSameType = isLinkBigInt === isStoredBigInt;
221
- for (let link of links) {
218
+ for (const link of links) {
222
219
  const linkId = (typeof link === 'object')
223
- ? (link = this.isObjectConnected(link) ? link.id : (await this.save(link)).id)
220
+ ? (this.isObjectConnected(link) ? link.id : (await this.save(link)).id)
224
221
  : link;
225
- if (!stored.includes(isSameType ? linkId : (isStoredBigInt ? BigInt(linkId) : Number(linkId)))) {
226
- await connection.query('INSERT INTO `' + linkTable + '` SET ' + objectColumn + ' = ?, ' + linkColumn + ' = ?', [objectId, linkId]);
227
- }
228
222
  saved.push(linkId);
223
+ if (stored.includes(linkId))
224
+ continue;
225
+ await connection.query('INSERT INTO `' + linkTable + '` SET ' + objectColumn + ' = ?, ' + linkColumn + ' = ?', [objectId, linkId]);
226
+ stored.push(linkId);
229
227
  }
230
- for (let storedId of stored) {
231
- if (!saved.includes(isSameType ? storedId : (isLinkBigInt ? BigInt(storedId) : Number(storedId)))) {
232
- await connection.query('DELETE FROM `' + linkTable + '` WHERE ' + objectColumn + ' = ? AND ' + linkColumn + ' = ?', [objectId, storedId]);
233
- }
228
+ for (const storedId of stored) {
229
+ if (saved.includes(storedId))
230
+ continue;
231
+ await connection.query('DELETE FROM `' + linkTable + '` WHERE ' + objectColumn + ' = ? AND ' + linkColumn + ' = ?', [objectId, storedId]);
234
232
  }
235
233
  }
236
234
  async search(type, search = {}) {
package/package.json CHANGED
@@ -58,5 +58,5 @@
58
58
  "build:esm": "tsc -p tsconfig.esm.json"
59
59
  },
60
60
  "types": "./esm/mysql.d.ts",
61
- "version": "0.0.16"
61
+ "version": "0.0.17"
62
62
  }