@itrocks/mysql 0.0.12 → 0.0.14

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.
package/cjs/mysql.js CHANGED
@@ -5,6 +5,7 @@ exports.mysqlDependsOn = mysqlDependsOn;
5
5
  const class_type_1 = require("@itrocks/class-type");
6
6
  const class_type_2 = require("@itrocks/class-type");
7
7
  const class_type_3 = require("@itrocks/class-type");
8
+ const property_type_1 = require("@itrocks/property-type");
8
9
  const reflect_1 = require("@itrocks/reflect");
9
10
  const reflect_2 = require("@itrocks/reflect");
10
11
  const storage_1 = require("@itrocks/storage");
@@ -51,7 +52,7 @@ class Mysql extends storage_1.DataSource {
51
52
  async deleteRelatedId(object, property, id) {
52
53
  const connection = this.connection ?? await this.connect();
53
54
  const objectTable = depends.storeOf(object);
54
- const propertyTable = depends.storeOf(new reflect_2.ReflectProperty(object, property).collectionType.elementType);
55
+ const propertyTable = depends.storeOf(new reflect_2.ReflectProperty(object, property).collectionType.elementType.type);
55
56
  const joinTable = [objectTable, propertyTable].sort().join('_');
56
57
  const query = 'DELETE FROM `' + joinTable + '` WHERE ' + objectTable + '_id = ? AND ' + propertyTable + '_id = ?';
57
58
  const values = [object.id, id];
@@ -77,7 +78,7 @@ class Mysql extends storage_1.DataSource {
77
78
  async insertRelatedId(object, property, id) {
78
79
  const connection = this.connection ?? await this.connect();
79
80
  const objectTable = depends.storeOf(object);
80
- const propertyTable = depends.storeOf(new reflect_2.ReflectProperty(object, property).collectionType.elementType);
81
+ const propertyTable = depends.storeOf(new reflect_2.ReflectProperty(object, property).collectionType.elementType.type);
81
82
  const joinTable = [objectTable, propertyTable].sort().join('_');
82
83
  const query = 'INSERT INTO `' + joinTable + '` SET ' + objectTable + '_id = ?, ' + propertyTable + '_id = ?';
83
84
  const values = [object.id, id];
@@ -109,7 +110,9 @@ class Mysql extends storage_1.DataSource {
109
110
  const sql = ['id'];
110
111
  for (const property of new reflect_1.ReflectClass(type).properties) {
111
112
  const propertyType = property.type;
112
- const propertyName = ((0, class_type_2.isAnyType)(propertyType) && depends.storeOf(propertyType))
113
+ if (propertyType instanceof property_type_1.CollectionType)
114
+ continue;
115
+ const propertyName = ((0, class_type_2.isAnyType)(propertyType.type) && depends.storeOf(propertyType.type))
113
116
  ? property.name + 'Id'
114
117
  : property.name;
115
118
  const columnName = depends.columnOf(propertyName);
@@ -127,7 +130,7 @@ class Mysql extends storage_1.DataSource {
127
130
  const rows = await connection.query('SELECT ' + propertiesSql + ' FROM `' + depends.storeOf(type) + '` WHERE id = ?', [id]);
128
131
  return this.valuesFromDb(rows[0], type);
129
132
  }
130
- async readCollection(object, property, type = new reflect_2.ReflectProperty(object, property).collectionType.elementType) {
133
+ async readCollection(object, property, type = new reflect_2.ReflectProperty(object, property).collectionType.elementType.type) {
131
134
  const connection = this.connection ?? await this.connect();
132
135
  const propertiesSql = this.propertiesToSqlSelect(type);
133
136
  const objectTable = depends.storeOf(object);
@@ -145,7 +148,7 @@ class Mysql extends storage_1.DataSource {
145
148
  const rows = await connection.query(query, [object.id]);
146
149
  return Promise.all(rows.map(row => this.valuesFromDb(row, type)));
147
150
  }
148
- async readCollectionIds(object, property, type = new reflect_2.ReflectProperty(object, property).collectionType.elementType) {
151
+ async readCollectionIds(object, property, type = new reflect_2.ReflectProperty(object, property).collectionType.elementType.type) {
149
152
  const connection = this.connection ?? await this.connect();
150
153
  const objectTable = depends.storeOf(object);
151
154
  const propertyTable = depends.storeOf(type);
package/esm/mysql.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { isAnyFunction } from '@itrocks/class-type';
2
2
  import { isAnyType } from '@itrocks/class-type';
3
3
  import { typeOf } from '@itrocks/class-type';
4
+ import { CollectionType } from '@itrocks/property-type';
4
5
  import { ReflectClass } from '@itrocks/reflect';
5
6
  import { ReflectProperty } from '@itrocks/reflect';
6
7
  import { DataSource } from '@itrocks/storage';
@@ -47,7 +48,7 @@ export class Mysql extends DataSource {
47
48
  async deleteRelatedId(object, property, id) {
48
49
  const connection = this.connection ?? await this.connect();
49
50
  const objectTable = depends.storeOf(object);
50
- const propertyTable = depends.storeOf(new ReflectProperty(object, property).collectionType.elementType);
51
+ const propertyTable = depends.storeOf(new ReflectProperty(object, property).collectionType.elementType.type);
51
52
  const joinTable = [objectTable, propertyTable].sort().join('_');
52
53
  const query = 'DELETE FROM `' + joinTable + '` WHERE ' + objectTable + '_id = ? AND ' + propertyTable + '_id = ?';
53
54
  const values = [object.id, id];
@@ -73,7 +74,7 @@ export class Mysql extends DataSource {
73
74
  async insertRelatedId(object, property, id) {
74
75
  const connection = this.connection ?? await this.connect();
75
76
  const objectTable = depends.storeOf(object);
76
- const propertyTable = depends.storeOf(new ReflectProperty(object, property).collectionType.elementType);
77
+ const propertyTable = depends.storeOf(new ReflectProperty(object, property).collectionType.elementType.type);
77
78
  const joinTable = [objectTable, propertyTable].sort().join('_');
78
79
  const query = 'INSERT INTO `' + joinTable + '` SET ' + objectTable + '_id = ?, ' + propertyTable + '_id = ?';
79
80
  const values = [object.id, id];
@@ -105,7 +106,9 @@ export class Mysql extends DataSource {
105
106
  const sql = ['id'];
106
107
  for (const property of new ReflectClass(type).properties) {
107
108
  const propertyType = property.type;
108
- const propertyName = (isAnyType(propertyType) && depends.storeOf(propertyType))
109
+ if (propertyType instanceof CollectionType)
110
+ continue;
111
+ const propertyName = (isAnyType(propertyType.type) && depends.storeOf(propertyType.type))
109
112
  ? property.name + 'Id'
110
113
  : property.name;
111
114
  const columnName = depends.columnOf(propertyName);
@@ -123,7 +126,7 @@ export class Mysql extends DataSource {
123
126
  const rows = await connection.query('SELECT ' + propertiesSql + ' FROM `' + depends.storeOf(type) + '` WHERE id = ?', [id]);
124
127
  return this.valuesFromDb(rows[0], type);
125
128
  }
126
- async readCollection(object, property, type = new ReflectProperty(object, property).collectionType.elementType) {
129
+ async readCollection(object, property, type = new ReflectProperty(object, property).collectionType.elementType.type) {
127
130
  const connection = this.connection ?? await this.connect();
128
131
  const propertiesSql = this.propertiesToSqlSelect(type);
129
132
  const objectTable = depends.storeOf(object);
@@ -141,7 +144,7 @@ export class Mysql extends DataSource {
141
144
  const rows = await connection.query(query, [object.id]);
142
145
  return Promise.all(rows.map(row => this.valuesFromDb(row, type)));
143
146
  }
144
- async readCollectionIds(object, property, type = new ReflectProperty(object, property).collectionType.elementType) {
147
+ async readCollectionIds(object, property, type = new ReflectProperty(object, property).collectionType.elementType.type) {
145
148
  const connection = this.connection ?? await this.connect();
146
149
  const objectTable = depends.storeOf(object);
147
150
  const propertyTable = depends.storeOf(type);
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.12"
61
+ "version": "0.0.14"
62
62
  }