@twin.org/entity-storage-connector-postgresql 0.0.3-next.2 → 0.0.3-next.20

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/docs/examples.md CHANGED
@@ -1 +1,98 @@
1
- # @twin.org/entity-storage-connector-postgresql - Examples
1
+ # Entity Storage Connector PostgreSQL Examples
2
+
3
+ These snippets demonstrate day-to-day usage with PostgreSQL, including setup, CRUD operations, conditional query calls, and table cleanup.
4
+
5
+ ## PostgreSqlEntityStorageConnector
6
+
7
+ ```typescript
8
+ import {
9
+ PostgreSqlEntityStorageConnector,
10
+ type IPostgreSqlEntityStorageConnectorConstructorOptions
11
+ } from '@twin.org/entity-storage-connector-postgresql';
12
+ import {
13
+ ComparisonOperator,
14
+ LogicalOperator,
15
+ SortDirection,
16
+ type EntityCondition
17
+ } from '@twin.org/entity';
18
+
19
+ interface Profile {
20
+ id: string;
21
+ email: string;
22
+ status: 'active' | 'inactive';
23
+ createdAt: string;
24
+ }
25
+
26
+ const options: IPostgreSqlEntityStorageConnectorConstructorOptions = {
27
+ entitySchema: 'Profile',
28
+ config: {
29
+ host: 'localhost',
30
+ port: 5432,
31
+ user: 'postgres',
32
+ password: 'postgres',
33
+ database: 'entity_storage',
34
+ tableName: 'profiles'
35
+ }
36
+ };
37
+
38
+ const connector = new PostgreSqlEntityStorageConnector<Profile>(options);
39
+ await connector.bootstrap();
40
+
41
+ const className = connector.className();
42
+ const schema = connector.getSchema();
43
+
44
+ await connector.set({
45
+ id: 'profile-1',
46
+ email: 'ada@example.com',
47
+ status: 'active',
48
+ createdAt: '2026-03-09T10:30:00.000Z'
49
+ });
50
+
51
+ const byPrimaryKey = await connector.get('profile-1');
52
+ const bySecondaryIndex = await connector.get('ada@example.com', 'email');
53
+
54
+ const activeCondition: EntityCondition<Profile> = {
55
+ logicalOperator: LogicalOperator.And,
56
+ conditions: [
57
+ {
58
+ property: 'status',
59
+ comparison: ComparisonOperator.Equals,
60
+ value: 'active'
61
+ }
62
+ ]
63
+ };
64
+
65
+ const result = await connector.query(
66
+ activeCondition,
67
+ [{ property: 'createdAt', sortDirection: SortDirection.Descending }],
68
+ ['id', 'email', 'status'],
69
+ undefined,
70
+ 25
71
+ );
72
+
73
+ await connector.remove('profile-1');
74
+ ```
75
+
76
+ ```typescript
77
+ import { PostgreSqlEntityStorageConnector } from '@twin.org/entity-storage-connector-postgresql';
78
+
79
+ interface Profile {
80
+ id: string;
81
+ email: string;
82
+ status: 'active' | 'inactive';
83
+ createdAt: string;
84
+ }
85
+
86
+ const connector = new PostgreSqlEntityStorageConnector<Profile>({
87
+ entitySchema: 'Profile',
88
+ config: {
89
+ host: 'localhost',
90
+ user: 'postgres',
91
+ password: 'postgres',
92
+ database: 'entity_storage',
93
+ tableName: 'profiles'
94
+ }
95
+ });
96
+
97
+ await connector.tableDrop();
98
+ ```
@@ -10,7 +10,7 @@ Class for performing entity storage operations using ql.
10
10
 
11
11
  ## Implements
12
12
 
13
- - `IEntityStorageConnector`\<`T`\>
13
+ - `IEntityStorageMigrationConnector`\<`T`\>
14
14
 
15
15
  ## Constructors
16
16
 
@@ -34,7 +34,7 @@ The options for the connector.
34
34
 
35
35
  ## Properties
36
36
 
37
- ### CLASS\_NAME
37
+ ### CLASS\_NAME {#class_name}
38
38
 
39
39
  > `readonly` `static` **CLASS\_NAME**: `string`
40
40
 
@@ -42,7 +42,7 @@ Runtime name for the class.
42
42
 
43
43
  ## Methods
44
44
 
45
- ### bootstrap()
45
+ ### bootstrap() {#bootstrap}
46
46
 
47
47
  > **bootstrap**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
48
48
 
@@ -64,11 +64,11 @@ A promise that resolves to a boolean indicating success.
64
64
 
65
65
  #### Implementation of
66
66
 
67
- `IEntityStorageConnector.bootstrap`
67
+ `IEntityStorageMigrationConnector.bootstrap`
68
68
 
69
69
  ***
70
70
 
71
- ### className()
71
+ ### className() {#classname}
72
72
 
73
73
  > **className**(): `string`
74
74
 
@@ -82,11 +82,47 @@ The class name of the component.
82
82
 
83
83
  #### Implementation of
84
84
 
85
- `IEntityStorageConnector.className`
85
+ `IEntityStorageMigrationConnector.className`
86
86
 
87
87
  ***
88
88
 
89
- ### getSchema()
89
+ ### health() {#health}
90
+
91
+ > **health**(): `Promise`\<`IHealth`[]\>
92
+
93
+ Get the health of the component.
94
+
95
+ #### Returns
96
+
97
+ `Promise`\<`IHealth`[]\>
98
+
99
+ The health of the component.
100
+
101
+ #### Implementation of
102
+
103
+ `IEntityStorageMigrationConnector.health`
104
+
105
+ ***
106
+
107
+ ### stop() {#stop}
108
+
109
+ > **stop**(): `Promise`\<`void`\>
110
+
111
+ The component needs to be stopped when the node is closed.
112
+
113
+ #### Returns
114
+
115
+ `Promise`\<`void`\>
116
+
117
+ Nothing.
118
+
119
+ #### Implementation of
120
+
121
+ `IEntityStorageMigrationConnector.stop`
122
+
123
+ ***
124
+
125
+ ### getSchema() {#getschema}
90
126
 
91
127
  > **getSchema**(): `IEntitySchema`
92
128
 
@@ -100,11 +136,11 @@ The schema for the entities.
100
136
 
101
137
  #### Implementation of
102
138
 
103
- `IEntityStorageConnector.getSchema`
139
+ `IEntityStorageMigrationConnector.getSchema`
104
140
 
105
141
  ***
106
142
 
107
- ### get()
143
+ ### get() {#get}
108
144
 
109
145
  > **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
110
146
 
@@ -138,11 +174,11 @@ The object if it can be found or undefined.
138
174
 
139
175
  #### Implementation of
140
176
 
141
- `IEntityStorageConnector.get`
177
+ `IEntityStorageMigrationConnector.get`
142
178
 
143
179
  ***
144
180
 
145
- ### set()
181
+ ### set() {#set}
146
182
 
147
183
  > **set**(`entity`, `conditions?`): `Promise`\<`void`\>
148
184
 
@@ -170,11 +206,55 @@ The id of the entity.
170
206
 
171
207
  #### Implementation of
172
208
 
173
- `IEntityStorageConnector.set`
209
+ `IEntityStorageMigrationConnector.set`
174
210
 
175
211
  ***
176
212
 
177
- ### remove()
213
+ ### setBatch() {#setbatch}
214
+
215
+ > **setBatch**(`entities`): `Promise`\<`void`\>
216
+
217
+ Set multiple entities in a batch.
218
+
219
+ #### Parameters
220
+
221
+ ##### entities
222
+
223
+ `T`[]
224
+
225
+ The entities to set.
226
+
227
+ #### Returns
228
+
229
+ `Promise`\<`void`\>
230
+
231
+ Nothing.
232
+
233
+ #### Implementation of
234
+
235
+ `IEntityStorageMigrationConnector.setBatch`
236
+
237
+ ***
238
+
239
+ ### empty() {#empty}
240
+
241
+ > **empty**(): `Promise`\<`void`\>
242
+
243
+ Empty all the entities.
244
+
245
+ #### Returns
246
+
247
+ `Promise`\<`void`\>
248
+
249
+ Nothing.
250
+
251
+ #### Implementation of
252
+
253
+ `IEntityStorageMigrationConnector.empty`
254
+
255
+ ***
256
+
257
+ ### remove() {#remove}
178
258
 
179
259
  > **remove**(`id`, `conditions?`): `Promise`\<`void`\>
180
260
 
@@ -202,11 +282,199 @@ Nothing.
202
282
 
203
283
  #### Implementation of
204
284
 
205
- `IEntityStorageConnector.remove`
285
+ `IEntityStorageMigrationConnector.remove`
286
+
287
+ ***
288
+
289
+ ### removeBatch() {#removebatch}
290
+
291
+ > **removeBatch**(`ids`): `Promise`\<`void`\>
292
+
293
+ Remove multiple entities by their primary key IDs.
294
+
295
+ #### Parameters
296
+
297
+ ##### ids
298
+
299
+ `string`[]
300
+
301
+ The ids of the entities to remove.
302
+
303
+ #### Returns
304
+
305
+ `Promise`\<`void`\>
306
+
307
+ Nothing.
308
+
309
+ #### Implementation of
310
+
311
+ `IEntityStorageMigrationConnector.removeBatch`
312
+
313
+ ***
314
+
315
+ ### teardown() {#teardown}
316
+
317
+ > **teardown**(`nodeLoggingComponentType?`): `Promise`\<`boolean`\>
318
+
319
+ Teardown the entity storage by dropping the table.
320
+
321
+ #### Parameters
322
+
323
+ ##### nodeLoggingComponentType?
324
+
325
+ `string`
326
+
327
+ The node logging component type.
328
+
329
+ #### Returns
330
+
331
+ `Promise`\<`boolean`\>
332
+
333
+ True if the teardown process was successful.
334
+
335
+ #### Implementation of
336
+
337
+ `IEntityStorageMigrationConnector.teardown`
338
+
339
+ ***
340
+
341
+ ### getPartitionContextIds() {#getpartitioncontextids}
342
+
343
+ > **getPartitionContextIds**(): `Promise`\<`IContextIds`[]\>
344
+
345
+ Get all the distinct partition context ids from the storage.
346
+
347
+ #### Returns
348
+
349
+ `Promise`\<`IContextIds`[]\>
350
+
351
+ An array of context id objects, one per unique partition.
352
+
353
+ #### Implementation of
354
+
355
+ `IEntityStorageMigrationConnector.getPartitionContextIds`
356
+
357
+ ***
358
+
359
+ ### createTargetConnector() {#createtargetconnector}
360
+
361
+ > **createTargetConnector**\<`U`\>(`entitySchemaName`): `Promise`\<`PostgreSqlEntityStorageConnector`\<`U`\>\>
362
+
363
+ Create a new target connector for the migration.
364
+
365
+ #### Type Parameters
366
+
367
+ ##### U
368
+
369
+ `U`
370
+
371
+ #### Parameters
372
+
373
+ ##### entitySchemaName
374
+
375
+ `string`
376
+
377
+ The entity schema name to use for the target connector.
378
+
379
+ #### Returns
380
+
381
+ `Promise`\<`PostgreSqlEntityStorageConnector`\<`U`\>\>
382
+
383
+ A new connector configured with a migration table name.
384
+
385
+ #### Implementation of
386
+
387
+ `IEntityStorageMigrationConnector.createTargetConnector`
206
388
 
207
389
  ***
208
390
 
209
- ### query()
391
+ ### finalizeMigration() {#finalizemigration}
392
+
393
+ > **finalizeMigration**\<`U`\>(`targetConnector`, `options?`, `loggingComponentType?`): `Promise`\<`PostgreSqlEntityStorageConnector`\<`U`\>\>
394
+
395
+ Finalize the migration by renaming the migration table to the original table name.
396
+
397
+ #### Type Parameters
398
+
399
+ ##### U
400
+
401
+ `U`
402
+
403
+ #### Parameters
404
+
405
+ ##### targetConnector
406
+
407
+ `PostgreSqlEntityStorageConnector`\<`U`\>
408
+
409
+ The connector pointing to the migration table.
410
+
411
+ ##### options?
412
+
413
+ `IMigrationOptions`\<`T`, `U`\>
414
+
415
+ The optional migration options.
416
+
417
+ ##### loggingComponentType?
418
+
419
+ `string`
420
+
421
+ The node logging component type.
422
+
423
+ #### Returns
424
+
425
+ `Promise`\<`PostgreSqlEntityStorageConnector`\<`U`\>\>
426
+
427
+ A connector pointing to the final (renamed) table.
428
+
429
+ #### Implementation of
430
+
431
+ `IEntityStorageMigrationConnector.finalizeMigration`
432
+
433
+ ***
434
+
435
+ ### cleanupMigration() {#cleanupmigration}
436
+
437
+ > **cleanupMigration**\<`U`\>(`targetConnector?`, `options?`, `loggingComponentType?`): `Promise`\<`void`\>
438
+
439
+ Clean up the migration by tearing down the migration table.
440
+
441
+ #### Type Parameters
442
+
443
+ ##### U
444
+
445
+ `U`
446
+
447
+ #### Parameters
448
+
449
+ ##### targetConnector?
450
+
451
+ `PostgreSqlEntityStorageConnector`\<`U`\>
452
+
453
+ The connector pointing to the migration table.
454
+
455
+ ##### options?
456
+
457
+ `IMigrationOptions`\<`T`, `U`\>
458
+
459
+ The optional migration options.
460
+
461
+ ##### loggingComponentType?
462
+
463
+ `string`
464
+
465
+ The node logging component type.
466
+
467
+ #### Returns
468
+
469
+ `Promise`\<`void`\>
470
+
471
+ #### Implementation of
472
+
473
+ `IEntityStorageMigrationConnector.cleanupMigration`
474
+
475
+ ***
476
+
477
+ ### query() {#query}
210
478
 
211
479
  > **query**(`conditions?`, `sortProperties?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `Partial`\<`T`\>[]; `cursor?`: `string`; \}\>
212
480
 
@@ -253,18 +521,30 @@ and a cursor which can be used to request more entities.
253
521
 
254
522
  #### Implementation of
255
523
 
256
- `IEntityStorageConnector.query`
524
+ `IEntityStorageMigrationConnector.query`
257
525
 
258
526
  ***
259
527
 
260
- ### tableDrop()
528
+ ### count() {#count}
529
+
530
+ > **count**(`conditions?`): `Promise`\<`number`\>
261
531
 
262
- > **tableDrop**(): `Promise`\<`void`\>
532
+ Count all the entities which match the conditions.
263
533
 
264
- Drop the table.
534
+ #### Parameters
535
+
536
+ ##### conditions?
537
+
538
+ `EntityCondition`\<`T`\>
539
+
540
+ The optional conditions to match for the entities.
265
541
 
266
542
  #### Returns
267
543
 
268
- `Promise`\<`void`\>
544
+ `Promise`\<`number`\>
269
545
 
270
- Nothing.
546
+ The total count of entities in the storage.
547
+
548
+ #### Implementation of
549
+
550
+ `IEntityStorageMigrationConnector.count`
@@ -4,7 +4,7 @@ Configuration for the PostgreSql Entity Storage Connector.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### host
7
+ ### host {#host}
8
8
 
9
9
  > **host**: `string`
10
10
 
@@ -12,15 +12,15 @@ The host for the PostgreSql instance.
12
12
 
13
13
  ***
14
14
 
15
- ### port?
15
+ ### port? {#port}
16
16
 
17
- > `optional` **port**: `number`
17
+ > `optional` **port?**: `number`
18
18
 
19
19
  The port for the PostgreSql instance.
20
20
 
21
21
  ***
22
22
 
23
- ### user
23
+ ### user {#user}
24
24
 
25
25
  > **user**: `string`
26
26
 
@@ -28,7 +28,7 @@ The user for the PostgreSql instance.
28
28
 
29
29
  ***
30
30
 
31
- ### password
31
+ ### password {#password}
32
32
 
33
33
  > **password**: `string`
34
34
 
@@ -36,7 +36,7 @@ The password for the PostgreSql instance.
36
36
 
37
37
  ***
38
38
 
39
- ### database
39
+ ### database {#database}
40
40
 
41
41
  > **database**: `string`
42
42
 
@@ -44,7 +44,7 @@ The name of the database to be used.
44
44
 
45
45
  ***
46
46
 
47
- ### tableName
47
+ ### tableName {#tablename}
48
48
 
49
49
  > **tableName**: `string`
50
50
 
@@ -4,7 +4,7 @@ The options for the PostgreSql entity storage connector constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### entitySchema
7
+ ### entitySchema {#entityschema}
8
8
 
9
9
  > **entitySchema**: `string`
10
10
 
@@ -12,17 +12,17 @@ The schema for the entity.
12
12
 
13
13
  ***
14
14
 
15
- ### partitionContextIds?
15
+ ### partitionContextIds? {#partitioncontextids}
16
16
 
17
- > `optional` **partitionContextIds**: `string`[]
17
+ > `optional` **partitionContextIds?**: `string`[]
18
18
 
19
19
  The keys to use from the context ids to create partitions.
20
20
 
21
21
  ***
22
22
 
23
- ### loggingComponentType?
23
+ ### loggingComponentType? {#loggingcomponenttype}
24
24
 
25
- > `optional` **loggingComponentType**: `string`
25
+ > `optional` **loggingComponentType?**: `string`
26
26
 
27
27
  The type of logging component to use.
28
28
 
@@ -34,7 +34,7 @@ logging
34
34
 
35
35
  ***
36
36
 
37
- ### config
37
+ ### config {#config}
38
38
 
39
39
  > **config**: [`IPostgreSqlEntityStorageConnectorConfig`](IPostgreSqlEntityStorageConnectorConfig.md)
40
40
 
package/locales/en.json CHANGED
@@ -4,7 +4,9 @@
4
4
  "databaseCreating": "Database \"{databaseName}\" creating",
5
5
  "databaseExists": "Database \"{databaseName}\" created or it already exists",
6
6
  "tableCreating": "Table \"{tableName}\" creating",
7
- "tableExists": "Table \"{tableName}\" created or it already exists"
7
+ "tableExists": "Table \"{tableName}\" created or it already exists",
8
+ "tableDropping": "Dropping table \"{tableName}\"",
9
+ "tableDropped": "Table \"{tableName}\" dropped"
8
10
  }
9
11
  },
10
12
  "error": {
@@ -16,7 +18,20 @@
16
18
  "queryFailed": "The query failed",
17
19
  "comparisonNotSupported": "Comparison operator \"{comparison}\" is not supported",
18
20
  "conditionalNotSupported": "Conditional operator \"{operator}\" is not supported",
19
- "entitySchemaPropertiesUndefined": "The entity schema properties are undefined"
21
+ "entitySchemaPropertiesUndefined": "The entity schema properties are undefined",
22
+ "setBatchFailed": "Unable to set batch of entities",
23
+ "countFailed": "Unable to count entities",
24
+ "emptyFailed": "Unable to empty entity storage",
25
+ "removeBatchFailed": "Unable to remove batch of entities",
26
+ "teardownFailed": "Unable to teardown entity storage",
27
+ "getPartitionContextIdsFailed": "Unable to get partition context ids",
28
+ "finalizeMigrationFailedBootstrap": "Finalizing migration failed during bootstrap phase"
29
+ }
30
+ },
31
+ "health": {
32
+ "postgreSqlEntityStorageConnector": {
33
+ "healthDescription": "Checks if the PostgreSQL table \"{tableName}\" is available",
34
+ "connectionFailed": "Failed to connect to PostgreSQL table \"{tableName}\""
20
35
  }
21
36
  }
22
37
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/entity-storage-connector-postgresql",
3
- "version": "0.0.3-next.2",
4
- "description": "Entity Storage connector implementation using PostgreSql storage",
3
+ "version": "0.0.3-next.20",
4
+ "description": "PostgreSQL connector for relational persistence and advanced SQL features.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/entity-storage.git",
7
+ "url": "git+https://github.com/iotaledger/twin-entity-storage.git",
8
8
  "directory": "packages/entity-storage-connector-postgresql"
9
9
  },
10
10
  "author": "adrian.sanchez.sequeira@iota.org",
@@ -17,10 +17,10 @@
17
17
  "@twin.org/context": "next",
18
18
  "@twin.org/core": "next",
19
19
  "@twin.org/entity": "next",
20
- "@twin.org/entity-storage-models": "0.0.3-next.2",
20
+ "@twin.org/entity-storage-models": "0.0.3-next.20",
21
21
  "@twin.org/logging-models": "next",
22
22
  "@twin.org/nameof": "next",
23
- "postgres": "3.4.7"
23
+ "postgres": "3.4.9"
24
24
  },
25
25
  "main": "./dist/es/index.js",
26
26
  "types": "./dist/types/index.d.ts",
@@ -54,7 +54,7 @@
54
54
  "integration"
55
55
  ],
56
56
  "bugs": {
57
- "url": "git+https://github.com/twinfoundation/entity-storage/issues"
57
+ "url": "git+https://github.com/iotaledger/twin-entity-storage/issues"
58
58
  },
59
59
  "homepage": "https://twindev.org"
60
60
  }