@twin.org/entity-storage-connector-mysql 0.0.1-next.18 → 0.0.1-next.19

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.
@@ -47,7 +47,7 @@ class MySqlEntityStorageConnector {
47
47
  core.Guards.stringValue(this.CLASS_NAME, "options.config.user", options.config.user);
48
48
  core.Guards.stringValue(this.CLASS_NAME, "options.config.password", options.config.password);
49
49
  core.Guards.stringValue(this.CLASS_NAME, "options.config.database", options.config.database);
50
- core.Guards.stringValue(this.CLASS_NAME, "options.config.table", options.config.table);
50
+ core.Guards.stringValue(this.CLASS_NAME, "options.config.tableName", options.config.tableName);
51
51
  this._entitySchema = entity.EntitySchemaFactory.get(options.entitySchema);
52
52
  this._config = options.config;
53
53
  }
@@ -80,14 +80,14 @@ class MySqlEntityStorageConnector {
80
80
  database: this._config.database
81
81
  }
82
82
  });
83
- await dbConnection.query(`CREATE TABLE IF NOT EXISTS \`${this._config.database}\`.\`${this._config.table}\` (${this.mapMySqlProperties(this._entitySchema)})`);
83
+ await dbConnection.query(`CREATE TABLE IF NOT EXISTS \`${this._config.database}\`.\`${this._config.tableName}\` (${this.mapMySqlProperties(this._entitySchema)})`);
84
84
  await nodeLogging?.log({
85
85
  level: "info",
86
86
  source: this.CLASS_NAME,
87
87
  ts: Date.now(),
88
88
  message: "tableExists",
89
89
  data: {
90
- table: this._config.table
90
+ table: this._config.tableName
91
91
  }
92
92
  });
93
93
  }
@@ -145,7 +145,7 @@ class MySqlEntityStorageConnector {
145
145
  values.push(condition.value);
146
146
  }
147
147
  }
148
- const query = `SELECT * FROM \`${this._config.database}\`.\`${this._config.table}\` WHERE ${whereClauses.join(" AND ")} LIMIT 1`;
148
+ const query = `SELECT * FROM \`${this._config.database}\`.\`${this._config.tableName}\` WHERE ${whereClauses.join(" AND ")} LIMIT 1`;
149
149
  const [rows] = await dbConnection.query(query, values);
150
150
  if (Array.isArray(rows) && rows.length === 1) {
151
151
  return rows[0];
@@ -182,7 +182,7 @@ class MySqlEntityStorageConnector {
182
182
  const values = Object.values(entity);
183
183
  const placeholders = values.map(() => "?").join(", ");
184
184
  const dbConnection = await this.createConnection();
185
- await dbConnection.query(`INSERT INTO \`${this._config.database}\`.\`${this._config.table}\` (${columns}) VALUES (${placeholders}) ON DUPLICATE KEY UPDATE ${columns
185
+ await dbConnection.query(`INSERT INTO \`${this._config.database}\`.\`${this._config.tableName}\` (${columns}) VALUES (${placeholders}) ON DUPLICATE KEY UPDATE ${columns
186
186
  .split(", ")
187
187
  .map(col => `${col} = VALUES(${col})`)
188
188
  .join(", ")};`, values.map(value => (typeof value === "object" ? JSON.stringify(value) : value)));
@@ -213,7 +213,7 @@ class MySqlEntityStorageConnector {
213
213
  return `\`${String(condition.property)}\` = ?`;
214
214
  });
215
215
  }
216
- const query = `DELETE FROM \`${this._config.database}\`.\`${this._config.table}\` WHERE \`id\` = ?${whereClauses.length > 0 ? ` AND ${whereClauses.join(" AND ")}` : ""}`;
216
+ const query = `DELETE FROM \`${this._config.database}\`.\`${this._config.tableName}\` WHERE \`id\` = ?${whereClauses.length > 0 ? ` AND ${whereClauses.join(" AND ")}` : ""}`;
217
217
  await dbConnection.query(query, values);
218
218
  }
219
219
  }
@@ -251,7 +251,7 @@ class MySqlEntityStorageConnector {
251
251
  if (conditions) {
252
252
  this.buildQueryParameters("", conditions, whereClauses, values);
253
253
  }
254
- const query = `SELECT ${properties ? properties.map(p => `\`${String(p)}\``).join(", ") : "*"} FROM \`${this._config.database}\`.\`${this._config.table}\` WHERE ${whereClauses.length > 0 ? whereClauses.join(" AND ") : "1"} ${orderByClause} LIMIT ${returnSize} OFFSET ${cursor ? Number(cursor) : 0}`;
254
+ const query = `SELECT ${properties ? properties.map(p => `\`${String(p)}\``).join(", ") : "*"} FROM \`${this._config.database}\`.\`${this._config.tableName}\` WHERE ${whereClauses.length > 0 ? whereClauses.join(" AND ") : "1"} ${orderByClause} LIMIT ${returnSize} OFFSET ${cursor ? Number(cursor) : 0}`;
255
255
  const dbConnection = await this.createConnection();
256
256
  const [rows] = (await dbConnection?.query(query, values)) ?? [];
257
257
  return {
@@ -272,7 +272,7 @@ class MySqlEntityStorageConnector {
272
272
  async tableDrop() {
273
273
  try {
274
274
  const dbConnection = await this.createConnection();
275
- await dbConnection?.query(`DROP TABLE \`${this._config.database}\`.\`${this._config.table}\`;`);
275
+ await dbConnection?.query(`DROP TABLE \`${this._config.database}\`.\`${this._config.tableName}\`;`);
276
276
  }
277
277
  catch {
278
278
  // Ignore errors
@@ -45,7 +45,7 @@ class MySqlEntityStorageConnector {
45
45
  Guards.stringValue(this.CLASS_NAME, "options.config.user", options.config.user);
46
46
  Guards.stringValue(this.CLASS_NAME, "options.config.password", options.config.password);
47
47
  Guards.stringValue(this.CLASS_NAME, "options.config.database", options.config.database);
48
- Guards.stringValue(this.CLASS_NAME, "options.config.table", options.config.table);
48
+ Guards.stringValue(this.CLASS_NAME, "options.config.tableName", options.config.tableName);
49
49
  this._entitySchema = EntitySchemaFactory.get(options.entitySchema);
50
50
  this._config = options.config;
51
51
  }
@@ -78,14 +78,14 @@ class MySqlEntityStorageConnector {
78
78
  database: this._config.database
79
79
  }
80
80
  });
81
- await dbConnection.query(`CREATE TABLE IF NOT EXISTS \`${this._config.database}\`.\`${this._config.table}\` (${this.mapMySqlProperties(this._entitySchema)})`);
81
+ await dbConnection.query(`CREATE TABLE IF NOT EXISTS \`${this._config.database}\`.\`${this._config.tableName}\` (${this.mapMySqlProperties(this._entitySchema)})`);
82
82
  await nodeLogging?.log({
83
83
  level: "info",
84
84
  source: this.CLASS_NAME,
85
85
  ts: Date.now(),
86
86
  message: "tableExists",
87
87
  data: {
88
- table: this._config.table
88
+ table: this._config.tableName
89
89
  }
90
90
  });
91
91
  }
@@ -143,7 +143,7 @@ class MySqlEntityStorageConnector {
143
143
  values.push(condition.value);
144
144
  }
145
145
  }
146
- const query = `SELECT * FROM \`${this._config.database}\`.\`${this._config.table}\` WHERE ${whereClauses.join(" AND ")} LIMIT 1`;
146
+ const query = `SELECT * FROM \`${this._config.database}\`.\`${this._config.tableName}\` WHERE ${whereClauses.join(" AND ")} LIMIT 1`;
147
147
  const [rows] = await dbConnection.query(query, values);
148
148
  if (Array.isArray(rows) && rows.length === 1) {
149
149
  return rows[0];
@@ -180,7 +180,7 @@ class MySqlEntityStorageConnector {
180
180
  const values = Object.values(entity);
181
181
  const placeholders = values.map(() => "?").join(", ");
182
182
  const dbConnection = await this.createConnection();
183
- await dbConnection.query(`INSERT INTO \`${this._config.database}\`.\`${this._config.table}\` (${columns}) VALUES (${placeholders}) ON DUPLICATE KEY UPDATE ${columns
183
+ await dbConnection.query(`INSERT INTO \`${this._config.database}\`.\`${this._config.tableName}\` (${columns}) VALUES (${placeholders}) ON DUPLICATE KEY UPDATE ${columns
184
184
  .split(", ")
185
185
  .map(col => `${col} = VALUES(${col})`)
186
186
  .join(", ")};`, values.map(value => (typeof value === "object" ? JSON.stringify(value) : value)));
@@ -211,7 +211,7 @@ class MySqlEntityStorageConnector {
211
211
  return `\`${String(condition.property)}\` = ?`;
212
212
  });
213
213
  }
214
- const query = `DELETE FROM \`${this._config.database}\`.\`${this._config.table}\` WHERE \`id\` = ?${whereClauses.length > 0 ? ` AND ${whereClauses.join(" AND ")}` : ""}`;
214
+ const query = `DELETE FROM \`${this._config.database}\`.\`${this._config.tableName}\` WHERE \`id\` = ?${whereClauses.length > 0 ? ` AND ${whereClauses.join(" AND ")}` : ""}`;
215
215
  await dbConnection.query(query, values);
216
216
  }
217
217
  }
@@ -249,7 +249,7 @@ class MySqlEntityStorageConnector {
249
249
  if (conditions) {
250
250
  this.buildQueryParameters("", conditions, whereClauses, values);
251
251
  }
252
- const query = `SELECT ${properties ? properties.map(p => `\`${String(p)}\``).join(", ") : "*"} FROM \`${this._config.database}\`.\`${this._config.table}\` WHERE ${whereClauses.length > 0 ? whereClauses.join(" AND ") : "1"} ${orderByClause} LIMIT ${returnSize} OFFSET ${cursor ? Number(cursor) : 0}`;
252
+ const query = `SELECT ${properties ? properties.map(p => `\`${String(p)}\``).join(", ") : "*"} FROM \`${this._config.database}\`.\`${this._config.tableName}\` WHERE ${whereClauses.length > 0 ? whereClauses.join(" AND ") : "1"} ${orderByClause} LIMIT ${returnSize} OFFSET ${cursor ? Number(cursor) : 0}`;
253
253
  const dbConnection = await this.createConnection();
254
254
  const [rows] = (await dbConnection?.query(query, values)) ?? [];
255
255
  return {
@@ -270,7 +270,7 @@ class MySqlEntityStorageConnector {
270
270
  async tableDrop() {
271
271
  try {
272
272
  const dbConnection = await this.createConnection();
273
- await dbConnection?.query(`DROP TABLE \`${this._config.database}\`.\`${this._config.table}\`;`);
273
+ await dbConnection?.query(`DROP TABLE \`${this._config.database}\`.\`${this._config.tableName}\`;`);
274
274
  }
275
275
  catch {
276
276
  // Ignore errors
@@ -25,5 +25,5 @@ export interface IMySqlEntityStorageConnectorConfig {
25
25
  /**
26
26
  * The name of the table to be used.
27
27
  */
28
- table: string;
28
+ tableName: string;
29
29
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/entity-storage-connector-mysql - Changelog
2
2
 
3
- ## v0.0.1-next.18
3
+ ## v0.0.1-next.19
4
4
 
5
5
  - Initial Release
@@ -44,8 +44,8 @@ The name of the database to be used.
44
44
 
45
45
  ***
46
46
 
47
- ### table
47
+ ### tableName
48
48
 
49
- > **table**: `string`
49
+ > **tableName**: `string`
50
50
 
51
51
  The name of the table to be used.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-mysql",
3
- "version": "0.0.1-next.18",
3
+ "version": "0.0.1-next.19",
4
4
  "description": "Entity Storage connector implementation using MySQL storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@twin.org/core": "next",
18
18
  "@twin.org/entity": "next",
19
- "@twin.org/entity-storage-models": "0.0.1-next.18",
19
+ "@twin.org/entity-storage-models": "0.0.1-next.19",
20
20
  "@twin.org/logging-models": "next",
21
21
  "@twin.org/nameof": "next",
22
22
  "mysql2": "^3.12.0"