@twin.org/entity-storage-connector-mysql 0.0.2-next.1 → 0.0.2-next.10
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/README.md +1 -1
- package/dist/cjs/index.cjs +48 -50
- package/dist/esm/index.mjs +49 -51
- package/dist/types/index.d.ts +1 -1
- package/dist/types/models/IMySqlEntityStorageConnectorConstructorOptions.d.ts +2 -2
- package/dist/types/mysqlEntityStorageConnector.d.ts +6 -6
- package/docs/changelog.md +145 -0
- package/docs/reference/classes/MySqlEntityStorageConnector.md +7 -11
- package/docs/reference/interfaces/IMySqlEntityStorageConnectorConstructorOptions.md +3 -3
- package/locales/en.json +4 -4
- package/package.json +23 -4
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm install @twin.org/entity-storage-connector-mysql
|
|
|
13
13
|
The tests developed are functional tests and need an instance of MySql up and running. To run MySql locally:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
docker run -p
|
|
16
|
+
docker run -p 3400:3306 --name twin-entity-storage-mysql --hostname mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Afterwards you can run the tests as follows:
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@twin.org/core');
|
|
4
4
|
var entity = require('@twin.org/entity');
|
|
5
|
-
var loggingModels = require('@twin.org/logging-models');
|
|
6
5
|
var promise = require('mysql2/promise');
|
|
7
6
|
|
|
8
7
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -12,14 +11,14 @@ var promise = require('mysql2/promise');
|
|
|
12
11
|
*/
|
|
13
12
|
class MySqlEntityStorageConnector {
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
14
|
+
* Runtime name for the class.
|
|
17
15
|
*/
|
|
18
|
-
static
|
|
16
|
+
static CLASS_NAME = "MySqlEntityStorageConnector";
|
|
19
17
|
/**
|
|
20
|
-
*
|
|
18
|
+
* Limit the number of entities when finding.
|
|
19
|
+
* @internal
|
|
21
20
|
*/
|
|
22
|
-
|
|
21
|
+
static _DEFAULT_LIMIT = 40;
|
|
23
22
|
/**
|
|
24
23
|
* The schema for the entity.
|
|
25
24
|
* @internal
|
|
@@ -40,71 +39,68 @@ class MySqlEntityStorageConnector {
|
|
|
40
39
|
* @param options The options for the connector.
|
|
41
40
|
*/
|
|
42
41
|
constructor(options) {
|
|
43
|
-
core.Guards.object(
|
|
44
|
-
core.Guards.stringValue(
|
|
45
|
-
core.Guards.object(
|
|
46
|
-
core.Guards.stringValue(
|
|
47
|
-
core.Guards.stringValue(
|
|
48
|
-
core.Guards.stringValue(
|
|
49
|
-
core.Guards.stringValue(
|
|
50
|
-
core.Guards.stringValue(
|
|
42
|
+
core.Guards.object(MySqlEntityStorageConnector.CLASS_NAME, "options", options);
|
|
43
|
+
core.Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.entitySchema", options.entitySchema);
|
|
44
|
+
core.Guards.object(MySqlEntityStorageConnector.CLASS_NAME, "options.config", options.config);
|
|
45
|
+
core.Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.host", options.config.host);
|
|
46
|
+
core.Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.user", options.config.user);
|
|
47
|
+
core.Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.password", options.config.password);
|
|
48
|
+
core.Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.database", options.config.database);
|
|
49
|
+
core.Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.tableName", options.config.tableName);
|
|
51
50
|
this._entitySchema = entity.EntitySchemaFactory.get(options.entitySchema);
|
|
52
51
|
this._config = options.config;
|
|
53
52
|
}
|
|
54
53
|
/**
|
|
55
54
|
* Initialize the MySql environment.
|
|
56
|
-
* @param
|
|
55
|
+
* @param nodeLoggingComponentType Optional type of the logging component.
|
|
57
56
|
* @returns A promise that resolves to a boolean indicating success.
|
|
58
57
|
*/
|
|
59
|
-
async bootstrap(
|
|
60
|
-
const nodeLogging =
|
|
58
|
+
async bootstrap(nodeLoggingComponentType) {
|
|
59
|
+
const nodeLogging = core.ComponentFactory.getIfExists(nodeLoggingComponentType);
|
|
61
60
|
try {
|
|
62
61
|
const dbConnection = await this.createConnection();
|
|
63
62
|
await nodeLogging?.log({
|
|
64
63
|
level: "info",
|
|
65
|
-
source:
|
|
64
|
+
source: MySqlEntityStorageConnector.CLASS_NAME,
|
|
66
65
|
ts: Date.now(),
|
|
67
66
|
message: "databaseCreating",
|
|
68
67
|
data: {
|
|
69
|
-
|
|
68
|
+
databaseName: this._config.database
|
|
70
69
|
}
|
|
71
70
|
});
|
|
72
71
|
// Create the database if it does not exist
|
|
73
72
|
await dbConnection.query(`CREATE DATABASE IF NOT EXISTS \`${this._config.database}\``);
|
|
74
73
|
await nodeLogging?.log({
|
|
75
74
|
level: "info",
|
|
76
|
-
source:
|
|
75
|
+
source: MySqlEntityStorageConnector.CLASS_NAME,
|
|
77
76
|
ts: Date.now(),
|
|
78
77
|
message: "databaseExists",
|
|
79
78
|
data: {
|
|
80
|
-
|
|
79
|
+
databaseName: this._config.database
|
|
81
80
|
}
|
|
82
81
|
});
|
|
83
82
|
await dbConnection.query(`CREATE TABLE IF NOT EXISTS \`${this._config.database}\`.\`${this._config.tableName}\` (${this.mapMySqlProperties(this._entitySchema)})`);
|
|
84
83
|
await nodeLogging?.log({
|
|
85
84
|
level: "info",
|
|
86
|
-
source:
|
|
85
|
+
source: MySqlEntityStorageConnector.CLASS_NAME,
|
|
87
86
|
ts: Date.now(),
|
|
88
87
|
message: "tableExists",
|
|
89
88
|
data: {
|
|
90
|
-
|
|
89
|
+
tableName: this._config.tableName
|
|
91
90
|
}
|
|
92
91
|
});
|
|
93
92
|
}
|
|
94
93
|
catch (error) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
94
|
+
await nodeLogging?.log({
|
|
95
|
+
level: "error",
|
|
96
|
+
source: MySqlEntityStorageConnector.CLASS_NAME,
|
|
97
|
+
ts: Date.now(),
|
|
98
|
+
message: "databaseCreateFailed",
|
|
99
|
+
error: core.BaseError.fromError(error),
|
|
100
|
+
data: {
|
|
101
|
+
databaseName: this._config.database
|
|
102
|
+
}
|
|
103
|
+
});
|
|
108
104
|
return false;
|
|
109
105
|
}
|
|
110
106
|
return true;
|
|
@@ -124,7 +120,7 @@ class MySqlEntityStorageConnector {
|
|
|
124
120
|
* @returns The object if it can be found or undefined.
|
|
125
121
|
*/
|
|
126
122
|
async get(id, secondaryIndex, conditions) {
|
|
127
|
-
core.Guards.stringValue(
|
|
123
|
+
core.Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "id", id);
|
|
128
124
|
try {
|
|
129
125
|
const dbConnection = await this.createConnection();
|
|
130
126
|
const whereClauses = [];
|
|
@@ -156,7 +152,7 @@ class MySqlEntityStorageConnector {
|
|
|
156
152
|
}
|
|
157
153
|
}
|
|
158
154
|
catch (err) {
|
|
159
|
-
throw new core.GeneralError(
|
|
155
|
+
throw new core.GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "getFailed", {
|
|
160
156
|
id
|
|
161
157
|
}, err);
|
|
162
158
|
}
|
|
@@ -169,7 +165,7 @@ class MySqlEntityStorageConnector {
|
|
|
169
165
|
* @returns The id of the entity.
|
|
170
166
|
*/
|
|
171
167
|
async set(entity$1, conditions) {
|
|
172
|
-
core.Guards.object(
|
|
168
|
+
core.Guards.object(MySqlEntityStorageConnector.CLASS_NAME, "entity", entity$1);
|
|
173
169
|
entity.EntitySchemaHelper.validateEntity(entity$1, this.getSchema());
|
|
174
170
|
const id = entity$1["id"];
|
|
175
171
|
try {
|
|
@@ -199,7 +195,7 @@ class MySqlEntityStorageConnector {
|
|
|
199
195
|
.join(", ")};`, values);
|
|
200
196
|
}
|
|
201
197
|
catch (err) {
|
|
202
|
-
throw new core.GeneralError(
|
|
198
|
+
throw new core.GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "setFailed", {
|
|
203
199
|
id
|
|
204
200
|
}, err);
|
|
205
201
|
}
|
|
@@ -211,7 +207,7 @@ class MySqlEntityStorageConnector {
|
|
|
211
207
|
* @returns Nothing.
|
|
212
208
|
*/
|
|
213
209
|
async remove(id, conditions) {
|
|
214
|
-
core.Guards.stringValue(
|
|
210
|
+
core.Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "id", id);
|
|
215
211
|
try {
|
|
216
212
|
const dbConnection = await this.createConnection();
|
|
217
213
|
const itemData = await this.get(id);
|
|
@@ -229,7 +225,7 @@ class MySqlEntityStorageConnector {
|
|
|
229
225
|
}
|
|
230
226
|
}
|
|
231
227
|
catch (err) {
|
|
232
|
-
throw new core.GeneralError(
|
|
228
|
+
throw new core.GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "removeFailed", {
|
|
233
229
|
id
|
|
234
230
|
}, err);
|
|
235
231
|
}
|
|
@@ -239,15 +235,15 @@ class MySqlEntityStorageConnector {
|
|
|
239
235
|
* @param conditions The conditions to match for the entities.
|
|
240
236
|
* @param sortProperties The optional sort order.
|
|
241
237
|
* @param properties The optional properties to return, defaults to all.
|
|
242
|
-
* @param cursor The cursor to request the next
|
|
243
|
-
* @param
|
|
238
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
239
|
+
* @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
244
240
|
* @returns All the entities for the storage matching the conditions,
|
|
245
241
|
* and a cursor which can be used to request more entities.
|
|
246
242
|
*/
|
|
247
|
-
async query(conditions, sortProperties, properties, cursor,
|
|
243
|
+
async query(conditions, sortProperties, properties, cursor, limit) {
|
|
248
244
|
const sql = "";
|
|
249
245
|
try {
|
|
250
|
-
const returnSize =
|
|
246
|
+
const returnSize = limit ?? MySqlEntityStorageConnector._DEFAULT_LIMIT;
|
|
251
247
|
let orderByClause = "";
|
|
252
248
|
if (Array.isArray(sortProperties)) {
|
|
253
249
|
const orderClauses = [];
|
|
@@ -273,7 +269,7 @@ class MySqlEntityStorageConnector {
|
|
|
273
269
|
};
|
|
274
270
|
}
|
|
275
271
|
catch (err) {
|
|
276
|
-
throw new core.GeneralError(
|
|
272
|
+
throw new core.GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "queryFailed", { sql }, err);
|
|
277
273
|
}
|
|
278
274
|
}
|
|
279
275
|
/**
|
|
@@ -398,7 +394,7 @@ class MySqlEntityStorageConnector {
|
|
|
398
394
|
else if (comparator.comparison === entity.ComparisonOperator.Includes) {
|
|
399
395
|
return `JSON_CONTAINS(\`${prop}\`, ?)`;
|
|
400
396
|
}
|
|
401
|
-
throw new core.GeneralError(
|
|
397
|
+
throw new core.GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "comparisonNotSupported", {
|
|
402
398
|
comparison: comparator.comparison
|
|
403
399
|
});
|
|
404
400
|
}
|
|
@@ -438,7 +434,9 @@ class MySqlEntityStorageConnector {
|
|
|
438
434
|
else if (operator === entity.LogicalOperator.Or) {
|
|
439
435
|
return "OR";
|
|
440
436
|
}
|
|
441
|
-
throw new core.GeneralError(
|
|
437
|
+
throw new core.GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "conditionalNotSupported", {
|
|
438
|
+
operator
|
|
439
|
+
});
|
|
442
440
|
}
|
|
443
441
|
/**
|
|
444
442
|
* Verify the conditions for the entity.
|
|
@@ -464,7 +462,7 @@ class MySqlEntityStorageConnector {
|
|
|
464
462
|
[entity.EntitySchemaPropertyType.Boolean]: "TINYINT(1)"
|
|
465
463
|
};
|
|
466
464
|
if (!entitySchema.properties) {
|
|
467
|
-
throw new core.GeneralError(
|
|
465
|
+
throw new core.GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "entitySchemaPropertiesUndefined");
|
|
468
466
|
}
|
|
469
467
|
const primaryKeys = [];
|
|
470
468
|
const columnDefinitions = entitySchema.properties
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Guards, BaseError, GeneralError, Is, ObjectHelper } from '@twin.org/core';
|
|
1
|
+
import { Guards, ComponentFactory, BaseError, GeneralError, Is, ObjectHelper } from '@twin.org/core';
|
|
2
2
|
import { EntitySchemaFactory, EntitySchemaHelper, EntitySchemaPropertyType, SortDirection, ComparisonOperator, LogicalOperator } from '@twin.org/entity';
|
|
3
|
-
import { LoggingConnectorFactory } from '@twin.org/logging-models';
|
|
4
3
|
import { createConnection } from 'mysql2/promise';
|
|
5
4
|
|
|
6
5
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -10,14 +9,14 @@ import { createConnection } from 'mysql2/promise';
|
|
|
10
9
|
*/
|
|
11
10
|
class MySqlEntityStorageConnector {
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @internal
|
|
12
|
+
* Runtime name for the class.
|
|
15
13
|
*/
|
|
16
|
-
static
|
|
14
|
+
static CLASS_NAME = "MySqlEntityStorageConnector";
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
16
|
+
* Limit the number of entities when finding.
|
|
17
|
+
* @internal
|
|
19
18
|
*/
|
|
20
|
-
|
|
19
|
+
static _DEFAULT_LIMIT = 40;
|
|
21
20
|
/**
|
|
22
21
|
* The schema for the entity.
|
|
23
22
|
* @internal
|
|
@@ -38,71 +37,68 @@ class MySqlEntityStorageConnector {
|
|
|
38
37
|
* @param options The options for the connector.
|
|
39
38
|
*/
|
|
40
39
|
constructor(options) {
|
|
41
|
-
Guards.object(
|
|
42
|
-
Guards.stringValue(
|
|
43
|
-
Guards.object(
|
|
44
|
-
Guards.stringValue(
|
|
45
|
-
Guards.stringValue(
|
|
46
|
-
Guards.stringValue(
|
|
47
|
-
Guards.stringValue(
|
|
48
|
-
Guards.stringValue(
|
|
40
|
+
Guards.object(MySqlEntityStorageConnector.CLASS_NAME, "options", options);
|
|
41
|
+
Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.entitySchema", options.entitySchema);
|
|
42
|
+
Guards.object(MySqlEntityStorageConnector.CLASS_NAME, "options.config", options.config);
|
|
43
|
+
Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.host", options.config.host);
|
|
44
|
+
Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.user", options.config.user);
|
|
45
|
+
Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.password", options.config.password);
|
|
46
|
+
Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.database", options.config.database);
|
|
47
|
+
Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "options.config.tableName", options.config.tableName);
|
|
49
48
|
this._entitySchema = EntitySchemaFactory.get(options.entitySchema);
|
|
50
49
|
this._config = options.config;
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
53
52
|
* Initialize the MySql environment.
|
|
54
|
-
* @param
|
|
53
|
+
* @param nodeLoggingComponentType Optional type of the logging component.
|
|
55
54
|
* @returns A promise that resolves to a boolean indicating success.
|
|
56
55
|
*/
|
|
57
|
-
async bootstrap(
|
|
58
|
-
const nodeLogging =
|
|
56
|
+
async bootstrap(nodeLoggingComponentType) {
|
|
57
|
+
const nodeLogging = ComponentFactory.getIfExists(nodeLoggingComponentType);
|
|
59
58
|
try {
|
|
60
59
|
const dbConnection = await this.createConnection();
|
|
61
60
|
await nodeLogging?.log({
|
|
62
61
|
level: "info",
|
|
63
|
-
source:
|
|
62
|
+
source: MySqlEntityStorageConnector.CLASS_NAME,
|
|
64
63
|
ts: Date.now(),
|
|
65
64
|
message: "databaseCreating",
|
|
66
65
|
data: {
|
|
67
|
-
|
|
66
|
+
databaseName: this._config.database
|
|
68
67
|
}
|
|
69
68
|
});
|
|
70
69
|
// Create the database if it does not exist
|
|
71
70
|
await dbConnection.query(`CREATE DATABASE IF NOT EXISTS \`${this._config.database}\``);
|
|
72
71
|
await nodeLogging?.log({
|
|
73
72
|
level: "info",
|
|
74
|
-
source:
|
|
73
|
+
source: MySqlEntityStorageConnector.CLASS_NAME,
|
|
75
74
|
ts: Date.now(),
|
|
76
75
|
message: "databaseExists",
|
|
77
76
|
data: {
|
|
78
|
-
|
|
77
|
+
databaseName: this._config.database
|
|
79
78
|
}
|
|
80
79
|
});
|
|
81
80
|
await dbConnection.query(`CREATE TABLE IF NOT EXISTS \`${this._config.database}\`.\`${this._config.tableName}\` (${this.mapMySqlProperties(this._entitySchema)})`);
|
|
82
81
|
await nodeLogging?.log({
|
|
83
82
|
level: "info",
|
|
84
|
-
source:
|
|
83
|
+
source: MySqlEntityStorageConnector.CLASS_NAME,
|
|
85
84
|
ts: Date.now(),
|
|
86
85
|
message: "tableExists",
|
|
87
86
|
data: {
|
|
88
|
-
|
|
87
|
+
tableName: this._config.tableName
|
|
89
88
|
}
|
|
90
89
|
});
|
|
91
90
|
}
|
|
92
91
|
catch (error) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
92
|
+
await nodeLogging?.log({
|
|
93
|
+
level: "error",
|
|
94
|
+
source: MySqlEntityStorageConnector.CLASS_NAME,
|
|
95
|
+
ts: Date.now(),
|
|
96
|
+
message: "databaseCreateFailed",
|
|
97
|
+
error: BaseError.fromError(error),
|
|
98
|
+
data: {
|
|
99
|
+
databaseName: this._config.database
|
|
100
|
+
}
|
|
101
|
+
});
|
|
106
102
|
return false;
|
|
107
103
|
}
|
|
108
104
|
return true;
|
|
@@ -122,7 +118,7 @@ class MySqlEntityStorageConnector {
|
|
|
122
118
|
* @returns The object if it can be found or undefined.
|
|
123
119
|
*/
|
|
124
120
|
async get(id, secondaryIndex, conditions) {
|
|
125
|
-
Guards.stringValue(
|
|
121
|
+
Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "id", id);
|
|
126
122
|
try {
|
|
127
123
|
const dbConnection = await this.createConnection();
|
|
128
124
|
const whereClauses = [];
|
|
@@ -154,7 +150,7 @@ class MySqlEntityStorageConnector {
|
|
|
154
150
|
}
|
|
155
151
|
}
|
|
156
152
|
catch (err) {
|
|
157
|
-
throw new GeneralError(
|
|
153
|
+
throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "getFailed", {
|
|
158
154
|
id
|
|
159
155
|
}, err);
|
|
160
156
|
}
|
|
@@ -167,7 +163,7 @@ class MySqlEntityStorageConnector {
|
|
|
167
163
|
* @returns The id of the entity.
|
|
168
164
|
*/
|
|
169
165
|
async set(entity, conditions) {
|
|
170
|
-
Guards.object(
|
|
166
|
+
Guards.object(MySqlEntityStorageConnector.CLASS_NAME, "entity", entity);
|
|
171
167
|
EntitySchemaHelper.validateEntity(entity, this.getSchema());
|
|
172
168
|
const id = entity["id"];
|
|
173
169
|
try {
|
|
@@ -197,7 +193,7 @@ class MySqlEntityStorageConnector {
|
|
|
197
193
|
.join(", ")};`, values);
|
|
198
194
|
}
|
|
199
195
|
catch (err) {
|
|
200
|
-
throw new GeneralError(
|
|
196
|
+
throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "setFailed", {
|
|
201
197
|
id
|
|
202
198
|
}, err);
|
|
203
199
|
}
|
|
@@ -209,7 +205,7 @@ class MySqlEntityStorageConnector {
|
|
|
209
205
|
* @returns Nothing.
|
|
210
206
|
*/
|
|
211
207
|
async remove(id, conditions) {
|
|
212
|
-
Guards.stringValue(
|
|
208
|
+
Guards.stringValue(MySqlEntityStorageConnector.CLASS_NAME, "id", id);
|
|
213
209
|
try {
|
|
214
210
|
const dbConnection = await this.createConnection();
|
|
215
211
|
const itemData = await this.get(id);
|
|
@@ -227,7 +223,7 @@ class MySqlEntityStorageConnector {
|
|
|
227
223
|
}
|
|
228
224
|
}
|
|
229
225
|
catch (err) {
|
|
230
|
-
throw new GeneralError(
|
|
226
|
+
throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "removeFailed", {
|
|
231
227
|
id
|
|
232
228
|
}, err);
|
|
233
229
|
}
|
|
@@ -237,15 +233,15 @@ class MySqlEntityStorageConnector {
|
|
|
237
233
|
* @param conditions The conditions to match for the entities.
|
|
238
234
|
* @param sortProperties The optional sort order.
|
|
239
235
|
* @param properties The optional properties to return, defaults to all.
|
|
240
|
-
* @param cursor The cursor to request the next
|
|
241
|
-
* @param
|
|
236
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
237
|
+
* @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
242
238
|
* @returns All the entities for the storage matching the conditions,
|
|
243
239
|
* and a cursor which can be used to request more entities.
|
|
244
240
|
*/
|
|
245
|
-
async query(conditions, sortProperties, properties, cursor,
|
|
241
|
+
async query(conditions, sortProperties, properties, cursor, limit) {
|
|
246
242
|
const sql = "";
|
|
247
243
|
try {
|
|
248
|
-
const returnSize =
|
|
244
|
+
const returnSize = limit ?? MySqlEntityStorageConnector._DEFAULT_LIMIT;
|
|
249
245
|
let orderByClause = "";
|
|
250
246
|
if (Array.isArray(sortProperties)) {
|
|
251
247
|
const orderClauses = [];
|
|
@@ -271,7 +267,7 @@ class MySqlEntityStorageConnector {
|
|
|
271
267
|
};
|
|
272
268
|
}
|
|
273
269
|
catch (err) {
|
|
274
|
-
throw new GeneralError(
|
|
270
|
+
throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "queryFailed", { sql }, err);
|
|
275
271
|
}
|
|
276
272
|
}
|
|
277
273
|
/**
|
|
@@ -396,7 +392,7 @@ class MySqlEntityStorageConnector {
|
|
|
396
392
|
else if (comparator.comparison === ComparisonOperator.Includes) {
|
|
397
393
|
return `JSON_CONTAINS(\`${prop}\`, ?)`;
|
|
398
394
|
}
|
|
399
|
-
throw new GeneralError(
|
|
395
|
+
throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "comparisonNotSupported", {
|
|
400
396
|
comparison: comparator.comparison
|
|
401
397
|
});
|
|
402
398
|
}
|
|
@@ -436,7 +432,9 @@ class MySqlEntityStorageConnector {
|
|
|
436
432
|
else if (operator === LogicalOperator.Or) {
|
|
437
433
|
return "OR";
|
|
438
434
|
}
|
|
439
|
-
throw new GeneralError(
|
|
435
|
+
throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "conditionalNotSupported", {
|
|
436
|
+
operator
|
|
437
|
+
});
|
|
440
438
|
}
|
|
441
439
|
/**
|
|
442
440
|
* Verify the conditions for the entity.
|
|
@@ -462,7 +460,7 @@ class MySqlEntityStorageConnector {
|
|
|
462
460
|
[EntitySchemaPropertyType.Boolean]: "TINYINT(1)"
|
|
463
461
|
};
|
|
464
462
|
if (!entitySchema.properties) {
|
|
465
|
-
throw new GeneralError(
|
|
463
|
+
throw new GeneralError(MySqlEntityStorageConnector.CLASS_NAME, "entitySchemaPropertiesUndefined");
|
|
466
464
|
}
|
|
467
465
|
const primaryKeys = [];
|
|
468
466
|
const columnDefinitions = entitySchema.properties
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ export interface IMySqlEntityStorageConnectorConstructorOptions {
|
|
|
8
8
|
*/
|
|
9
9
|
entitySchema: string;
|
|
10
10
|
/**
|
|
11
|
-
* The type of logging
|
|
11
|
+
* The type of logging component to use.
|
|
12
12
|
* @default logging
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
loggingComponentType?: string;
|
|
15
15
|
/**
|
|
16
16
|
* The configuration for the connector.
|
|
17
17
|
*/
|
|
@@ -8,7 +8,7 @@ export declare class MySqlEntityStorageConnector<T = unknown> implements IEntity
|
|
|
8
8
|
/**
|
|
9
9
|
* Runtime name for the class.
|
|
10
10
|
*/
|
|
11
|
-
readonly CLASS_NAME: string;
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
12
|
/**
|
|
13
13
|
* Create a new instance of MySqlEntityStorageConnector.
|
|
14
14
|
* @param options The options for the connector.
|
|
@@ -16,10 +16,10 @@ export declare class MySqlEntityStorageConnector<T = unknown> implements IEntity
|
|
|
16
16
|
constructor(options: IMySqlEntityStorageConnectorConstructorOptions);
|
|
17
17
|
/**
|
|
18
18
|
* Initialize the MySql environment.
|
|
19
|
-
* @param
|
|
19
|
+
* @param nodeLoggingComponentType Optional type of the logging component.
|
|
20
20
|
* @returns A promise that resolves to a boolean indicating success.
|
|
21
21
|
*/
|
|
22
|
-
bootstrap(
|
|
22
|
+
bootstrap(nodeLoggingComponentType?: string): Promise<boolean>;
|
|
23
23
|
/**
|
|
24
24
|
* Get the schema for the entities.
|
|
25
25
|
* @returns The schema for the entities.
|
|
@@ -61,15 +61,15 @@ export declare class MySqlEntityStorageConnector<T = unknown> implements IEntity
|
|
|
61
61
|
* @param conditions The conditions to match for the entities.
|
|
62
62
|
* @param sortProperties The optional sort order.
|
|
63
63
|
* @param properties The optional properties to return, defaults to all.
|
|
64
|
-
* @param cursor The cursor to request the next
|
|
65
|
-
* @param
|
|
64
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
65
|
+
* @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.
|
|
66
66
|
* @returns All the entities for the storage matching the conditions,
|
|
67
67
|
* and a cursor which can be used to request more entities.
|
|
68
68
|
*/
|
|
69
69
|
query(conditions?: EntityCondition<T>, sortProperties?: {
|
|
70
70
|
property: keyof T;
|
|
71
71
|
sortDirection: SortDirection;
|
|
72
|
-
}[], properties?: (keyof T)[], cursor?: string,
|
|
72
|
+
}[], properties?: (keyof T)[], cursor?: string, limit?: number): Promise<{
|
|
73
73
|
entities: Partial<T>[];
|
|
74
74
|
cursor?: string;
|
|
75
75
|
}>;
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,150 @@
|
|
|
1
1
|
# @twin.org/entity-storage-connector-mysql - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.10](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.9...entity-storage-connector-mysql-v0.0.2-next.10) (2025-10-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add validate-locales ([e66ef0d](https://github.com/twinfoundation/entity-storage/commit/e66ef0de26ca2f82b3fe89bb5c7a15a0978a9644))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
18
|
+
|
|
19
|
+
## [0.0.2-next.9](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.8...entity-storage-connector-mysql-v0.0.2-next.9) (2025-10-02)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Miscellaneous Chores
|
|
23
|
+
|
|
24
|
+
* **entity-storage-connector-mysql:** Synchronize repo versions
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* The following workspace dependencies were updated
|
|
30
|
+
* dependencies
|
|
31
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
32
|
+
* devDependencies
|
|
33
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
34
|
+
|
|
35
|
+
## [0.0.2-next.8](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.7...entity-storage-connector-mysql-v0.0.2-next.8) (2025-08-29)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
|
|
40
|
+
* eslint migration to flat config ([f033b64](https://github.com/twinfoundation/entity-storage/commit/f033b64984c0e6a8129d929c9dd816dcc1b8dab0))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Dependencies
|
|
44
|
+
|
|
45
|
+
* The following workspace dependencies were updated
|
|
46
|
+
* dependencies
|
|
47
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
48
|
+
* devDependencies
|
|
49
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
50
|
+
|
|
51
|
+
## [0.0.2-next.7](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.6...entity-storage-connector-mysql-v0.0.2-next.7) (2025-08-20)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Features
|
|
55
|
+
|
|
56
|
+
* logging naming consistency ([f99d12d](https://github.com/twinfoundation/entity-storage/commit/f99d12dea04b6d4f2b5632ff5473e9ec7d5f9055))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Dependencies
|
|
60
|
+
|
|
61
|
+
* The following workspace dependencies were updated
|
|
62
|
+
* dependencies
|
|
63
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
64
|
+
* devDependencies
|
|
65
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
66
|
+
|
|
67
|
+
## [0.0.2-next.6](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.5...entity-storage-connector-mysql-v0.0.2-next.6) (2025-08-19)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### Features
|
|
71
|
+
|
|
72
|
+
* update framework core ([b59a380](https://github.com/twinfoundation/entity-storage/commit/b59a380bb7fba2b43610f69074dcdee24a4737da))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### Dependencies
|
|
76
|
+
|
|
77
|
+
* The following workspace dependencies were updated
|
|
78
|
+
* dependencies
|
|
79
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
80
|
+
* devDependencies
|
|
81
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
82
|
+
|
|
83
|
+
## [0.0.2-next.5](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.4...entity-storage-connector-mysql-v0.0.2-next.5) (2025-08-11)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### Miscellaneous Chores
|
|
87
|
+
|
|
88
|
+
* **entity-storage-connector-mysql:** Synchronize repo versions
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
### Dependencies
|
|
92
|
+
|
|
93
|
+
* The following workspace dependencies were updated
|
|
94
|
+
* dependencies
|
|
95
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
96
|
+
* devDependencies
|
|
97
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
98
|
+
|
|
99
|
+
## [0.0.2-next.4](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.3...entity-storage-connector-mysql-v0.0.2-next.4) (2025-08-08)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### Miscellaneous Chores
|
|
103
|
+
|
|
104
|
+
* **entity-storage-connector-mysql:** Synchronize repo versions
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
### Dependencies
|
|
108
|
+
|
|
109
|
+
* The following workspace dependencies were updated
|
|
110
|
+
* dependencies
|
|
111
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
112
|
+
* devDependencies
|
|
113
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
114
|
+
|
|
115
|
+
## [0.0.2-next.3](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.2...entity-storage-connector-mysql-v0.0.2-next.3) (2025-07-25)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### Miscellaneous Chores
|
|
119
|
+
|
|
120
|
+
* **entity-storage-connector-mysql:** Synchronize repo versions
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
### Dependencies
|
|
124
|
+
|
|
125
|
+
* The following workspace dependencies were updated
|
|
126
|
+
* dependencies
|
|
127
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
128
|
+
* devDependencies
|
|
129
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
130
|
+
|
|
131
|
+
## [0.0.2-next.2](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.1...entity-storage-connector-mysql-v0.0.2-next.2) (2025-07-24)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
### Features
|
|
135
|
+
|
|
136
|
+
* remove includeNodeIdentity flag ([d88d1d0](https://github.com/twinfoundation/entity-storage/commit/d88d1d0694419b795dc860e0b712a0051c9a1c9e))
|
|
137
|
+
* synchronised storage ([#44](https://github.com/twinfoundation/entity-storage/issues/44)) ([94e10e2](https://github.com/twinfoundation/entity-storage/commit/94e10e26d1feec801449dc04af7a9757ac7495ff))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
### Dependencies
|
|
141
|
+
|
|
142
|
+
* The following workspace dependencies were updated
|
|
143
|
+
* dependencies
|
|
144
|
+
* @twin.org/entity-storage-models bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
145
|
+
* devDependencies
|
|
146
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
147
|
+
|
|
3
148
|
## [0.0.2-next.1](https://github.com/twinfoundation/entity-storage/compare/entity-storage-connector-mysql-v0.0.2-next.0...entity-storage-connector-mysql-v0.0.2-next.1) (2025-07-17)
|
|
4
149
|
|
|
5
150
|
|
|
@@ -36,29 +36,25 @@ The options for the connector.
|
|
|
36
36
|
|
|
37
37
|
### CLASS\_NAME
|
|
38
38
|
|
|
39
|
-
> `readonly` **CLASS\_NAME**: `string`
|
|
39
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
40
40
|
|
|
41
41
|
Runtime name for the class.
|
|
42
42
|
|
|
43
|
-
#### Implementation of
|
|
44
|
-
|
|
45
|
-
`IEntityStorageConnector.CLASS_NAME`
|
|
46
|
-
|
|
47
43
|
## Methods
|
|
48
44
|
|
|
49
45
|
### bootstrap()
|
|
50
46
|
|
|
51
|
-
> **bootstrap**(`
|
|
47
|
+
> **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
|
|
52
48
|
|
|
53
49
|
Initialize the MySql environment.
|
|
54
50
|
|
|
55
51
|
#### Parameters
|
|
56
52
|
|
|
57
|
-
#####
|
|
53
|
+
##### nodeLoggingComponentType?
|
|
58
54
|
|
|
59
55
|
`string`
|
|
60
56
|
|
|
61
|
-
Optional type of the logging
|
|
57
|
+
Optional type of the logging component.
|
|
62
58
|
|
|
63
59
|
#### Returns
|
|
64
60
|
|
|
@@ -194,7 +190,7 @@ Nothing.
|
|
|
194
190
|
|
|
195
191
|
### query()
|
|
196
192
|
|
|
197
|
-
> **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `
|
|
193
|
+
> **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
|
|
198
194
|
|
|
199
195
|
Find all the entities which match the conditions.
|
|
200
196
|
|
|
@@ -222,9 +218,9 @@ The optional properties to return, defaults to all.
|
|
|
222
218
|
|
|
223
219
|
`string`
|
|
224
220
|
|
|
225
|
-
The cursor to request the next
|
|
221
|
+
The cursor to request the next chunk of entities.
|
|
226
222
|
|
|
227
|
-
#####
|
|
223
|
+
##### limit?
|
|
228
224
|
|
|
229
225
|
`number`
|
|
230
226
|
|
|
@@ -12,11 +12,11 @@ The schema for the entity.
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
###
|
|
15
|
+
### loggingComponentType?
|
|
16
16
|
|
|
17
|
-
> `optional` **
|
|
17
|
+
> `optional` **loggingComponentType**: `string`
|
|
18
18
|
|
|
19
|
-
The type of logging
|
|
19
|
+
The type of logging component to use.
|
|
20
20
|
|
|
21
21
|
#### Default
|
|
22
22
|
|
package/locales/en.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"info": {
|
|
3
|
-
"
|
|
3
|
+
"mySqlEntityStorageConnector": {
|
|
4
4
|
"databaseCreating": "Database \"{databaseName}\" creating",
|
|
5
5
|
"databaseExists": "Database \"{databaseName}\" created or it already exists",
|
|
6
6
|
"tableExists": "Database \"{tableName}\" created or it already exists"
|
|
7
7
|
}
|
|
8
8
|
},
|
|
9
9
|
"error": {
|
|
10
|
-
"
|
|
10
|
+
"mySqlEntityStorageConnector": {
|
|
11
11
|
"setFailed": "Unable to set entity \"{id}\"",
|
|
12
12
|
"getFailed": "Unable to get entity \"{id}\"",
|
|
13
13
|
"removeFailed": "Unable to remove entity \"{id}\"",
|
|
14
14
|
"queryFailed": "The query failed",
|
|
15
15
|
"comparisonNotSupported": "Comparison operator \"{comparison}\" is not supported",
|
|
16
16
|
"conditionalNotSupported": "Conditional operator \"{operator}\" is not supported",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"entitySchemaPropertiesUndefined": "The entity schema properties are undefined",
|
|
18
|
+
"databaseCreateFailed": "Unable to create database \"{databaseName}\""
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-connector-mysql",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.10",
|
|
4
4
|
"description": "Entity Storage connector implementation using MySQL storage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"@twin.org/core": "next",
|
|
18
18
|
"@twin.org/data-json-ld": "next",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
|
-
"@twin.org/entity-storage-models": "0.0.2-next.
|
|
20
|
+
"@twin.org/entity-storage-models": "0.0.2-next.10",
|
|
21
21
|
"@twin.org/logging-models": "next",
|
|
22
22
|
"@twin.org/nameof": "next",
|
|
23
|
-
"mysql2": "3.
|
|
23
|
+
"mysql2": "3.15.2"
|
|
24
24
|
},
|
|
25
25
|
"main": "./dist/cjs/index.cjs",
|
|
26
26
|
"module": "./dist/esm/index.mjs",
|
|
@@ -39,5 +39,24 @@
|
|
|
39
39
|
"dist/types",
|
|
40
40
|
"locales",
|
|
41
41
|
"docs"
|
|
42
|
-
]
|
|
42
|
+
],
|
|
43
|
+
"keywords": [
|
|
44
|
+
"twin",
|
|
45
|
+
"trade",
|
|
46
|
+
"iota",
|
|
47
|
+
"framework",
|
|
48
|
+
"blockchain",
|
|
49
|
+
"entity-storage",
|
|
50
|
+
"entity",
|
|
51
|
+
"storage",
|
|
52
|
+
"persistence",
|
|
53
|
+
"database",
|
|
54
|
+
"connector",
|
|
55
|
+
"adapter",
|
|
56
|
+
"integration"
|
|
57
|
+
],
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "git+https://github.com/twinfoundation/entity-storage/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://twindev.org"
|
|
43
62
|
}
|