@stonyx/orm 0.3.2-beta.66 → 0.3.2-beta.67
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 +35 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ A lightweight ORM for Stonyx projects, featuring model definitions, serializers,
|
|
|
13
13
|
- **Models**: Define attributes with type-safe proxies (`attr`) and relationships (`hasMany`, `belongsTo`).
|
|
14
14
|
- **Serializers**: Map raw data into model-friendly structures, including nested properties.
|
|
15
15
|
- **Transforms**: Apply custom transformations on data values automatically.
|
|
16
|
-
- **DB Integration**: Optional file-based persistence with auto-save support, or MySQL for production workloads.
|
|
16
|
+
- **DB Integration**: Optional file-based persistence with auto-save support, or MySQL/PostgreSQL/TimescaleDB/DynamoDB for production workloads.
|
|
17
17
|
- **REST Server Integration**: Automatic route setup with customizable access control.
|
|
18
18
|
- **Lifecycle Hooks**: Middleware-based before/after hooks for validation, authorization, side effects, and auditing.
|
|
19
19
|
|
|
@@ -65,13 +65,16 @@ const {
|
|
|
65
65
|
MYSQL_DATABASE,
|
|
66
66
|
MYSQL_CONNECTION_LIMIT,
|
|
67
67
|
MYSQL_MIGRATIONS_DIR,
|
|
68
|
+
DYNAMODB_REGION,
|
|
69
|
+
DYNAMODB_ENDPOINT,
|
|
70
|
+
DYNAMODB_TABLE_PREFIX,
|
|
68
71
|
} = process.env;
|
|
69
72
|
|
|
70
73
|
export default {
|
|
71
74
|
orm: {
|
|
72
75
|
logColor: 'white',
|
|
73
76
|
logMethod: 'db',
|
|
74
|
-
|
|
77
|
+
|
|
75
78
|
db: {
|
|
76
79
|
autosave: DB_AUTO_SAVE ?? 'false',
|
|
77
80
|
file: DB_FILE ?? 'db.json',
|
|
@@ -96,6 +99,11 @@ export default {
|
|
|
96
99
|
migrationsDir: MYSQL_MIGRATIONS_DIR ?? 'migrations',
|
|
97
100
|
migrationsTable: '__migrations',
|
|
98
101
|
} : undefined,
|
|
102
|
+
dynamodb: DYNAMODB_REGION ? {
|
|
103
|
+
region: DYNAMODB_REGION,
|
|
104
|
+
endpoint: DYNAMODB_ENDPOINT, // optional, for DynamoDB Local
|
|
105
|
+
tablePrefix: DYNAMODB_TABLE_PREFIX, // optional table name prefix
|
|
106
|
+
} : undefined,
|
|
99
107
|
restServer: {
|
|
100
108
|
enabled: ORM_USE_REST_SERVER ?? 'true',
|
|
101
109
|
route: ORM_REST_ROUTE ?? '/'
|
|
@@ -243,6 +251,31 @@ Set the `MYSQL_HOST` environment variable to enable MySQL persistence. The ORM l
|
|
|
243
251
|
| `stonyx db:migrate` | Apply pending migrations |
|
|
244
252
|
| `stonyx db:migrate:rollback` | Rollback the most recent migration |
|
|
245
253
|
| `stonyx db:migrate:status` | Show migration status |
|
|
254
|
+
| `stonyx db:sync` | Sync DynamoDB table definitions to match current model schemas |
|
|
255
|
+
|
|
256
|
+
### DynamoDB Mode
|
|
257
|
+
|
|
258
|
+
Set the `DYNAMODB_REGION` environment variable to enable DynamoDB persistence. Tables are created with PAY_PER_REQUEST (on-demand) billing. Global Secondary Indexes (GSIs) are auto-provisioned at startup based on model `belongsTo` relationships — each FK column gets a GSI. `findAll()` with conditions routes to a GSI Query when the condition key matches a GSI partition key; non-indexed attribute conditions fall back to Scan + FilterExpression (expensive for large tables). ULID generation replaces auto-increment for numeric-ID models.
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
dynamodb: {
|
|
262
|
+
region: 'us-east-1',
|
|
263
|
+
endpoint: 'http://localhost:8000', // optional, for DynamoDB Local
|
|
264
|
+
tablePrefix: 'myapp-', // optional table name prefix
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Environment variables:
|
|
269
|
+
|
|
270
|
+
* `DYNAMODB_REGION`: AWS region for DynamoDB (e.g., `'us-east-1'`).
|
|
271
|
+
* `DYNAMODB_ENDPOINT`: Optional custom endpoint URL, useful for DynamoDB Local during development.
|
|
272
|
+
* `DYNAMODB_TABLE_PREFIX`: Optional prefix prepended to all table names (e.g., `'myapp-'` yields `'myapp-animals'`).
|
|
273
|
+
|
|
274
|
+
**Peer dependencies:** `@aws-sdk/client-dynamodb` and `@aws-sdk/lib-dynamodb` must be installed when using the DynamoDB driver. The AWS SDK is dynamically imported and only loaded when the DynamoDB driver is selected.
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
npm install @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
|
|
278
|
+
```
|
|
246
279
|
|
|
247
280
|
### Running MySQL Tests
|
|
248
281
|
|