feat(javascript): Add Sequelize ORM sample for Aurora DSQL - #1845
lasitab-code wants to merge 1 commit into
Conversation
Add a Node.js hotel-reservation sample using Sequelize with Aurora DSQL. Integrates the Aurora DSQL node-postgres connector via Sequelize's dialectModule for automatic IAM token generation and Region discovery. Demonstrates schema-qualified models, foreign keys, OCC retry, and both admin and non-admin (least-privilege) connection paths. Verified live on admin and non-admin users; 18 unit tests and 5 integration tests pass. sim: https://issues.amazon.com/issues/DBBLOG-5678
There was a problem hiding this comment.
Ran end-to-end on a real DSQL cluster - clean run, 4 FKs enforced, real OCC retry. Substance is solid; blockers are inline. Non-blocking:
| Type | Where | Issue | Fix |
|---|---|---|---|
| should-fix | README.md:180 |
"write paths use the OCC retry helper" — only 1 of ~10 writes does. Wrap or soften. | Wrap the multi-step writes in withOccRetry, or reword to "…surface as retryable serialization errors — see retry.js, demonstrated on the loyalty-tier update". |
| should-fix | package.json |
@aws-sdk/credential-providers + dsql-signer never imported — drop; regen lockfile (npm ci errors today). |
npm uninstall @aws-sdk/credential-providers @aws-sdk/dsql-signer — drops both and syncs the lockfile in one step (verified: npm ci then passes, unit tests green; the connector still pulls both transitively). |
| should-fix | setup_app_user.sql:46-49 |
ADP rationale wrong: owners can't be denied own tables, and admin's ADP never covers app-created ones. Keep grant, fix comment. | Replace "Without this, the app hits permission denied on its own tables." with: this covers tables admin creates later in the schema; tables the app creates it already owns. |
| nit | db.js:78 |
createSchema() creates tables → createTables(). |
7 occurrences in 3 files: db.js:78,155; app.js:6,189; test/integration.test.js:32,39,45. |
| nit | README.md:183 |
Connector's occ-retry only wraps connect(); retry.js is the real mechanism — worth a line. |
Add a clause to adaptation 5 — it explains why retry.js exists. |
| nit | test/test_example.test.js:39 |
Backoff timing unasserted (counts/give-up well covered). | Spy on setTimeout, force 3 OCC failures, assert each delay is in [50·2^i, 100·2^i) — covers exponent and jitter. |
| nit | headers | SPDX Apache-2.0 vs package.json MIT-0 — align. |
Switch the 8 headers to MIT-0 (matches LICENSE, package.json:36, README.md:235), though other samples are mixed. |
| console.log('\n✓ Demo completed successfully!'); | ||
| } | ||
|
|
||
| main().catch((err) => { |
There was a problem hiding this comment.
No test executes this file — main() runs at import and nothing is exported, so both suites only test the helpers. Verified: injected a ~24% billing bug and a crash bug; all 23 tests stayed green both times.
Suggest the sibling pattern (node-postgres, batch_operations):
export { main };
if (import.meta.url === `file://${process.argv[1]}`) {
main().catch((err) => { console.error(err); process.exit(1); });
}then run main() from the integration test.
| clientMinMessages: 'ignore', | ||
| }, | ||
| // Route all queries to the selected schema (public for admin, custom for non-admin). | ||
| searchPath: SCHEMA, |
There was a problem hiding this comment.
searchPath makes Sequelize disable bind parameters — every model INSERT/UPDATE ships values inlined as literals (verified on the wire). Deleting this line restores $1, $2, … and queries stay schema-qualified via each model's schema: option. Ran the sample without it — identical behavior.
| # Generate an admin auth token | ||
| TOKEN=$(aws dsql generate-db-connect-admin-auth-token \ | ||
| --hostname $CLUSTER_ENDPOINT \ | ||
| --region $CLUSTER_REGION \ |
There was a problem hiding this comment.
Three documented steps fail as written:
- Here —
CLUSTER_REGIONis "optional" per line 45 but this snippet requires it. - Line 213 — FK query filters
table_schema = 'public'; the recommendedhotel-schema path returns 0 rows vs "Expect four foreign keys". setup_app_user.sql:38— "run the app with CLUSTER_USER=admin" can't create thehoteltables;db.js:28-30forces admin topublic.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT-0 license.
Summary
Adds a Node.js sample demonstrating Sequelize ORM with Aurora DSQL, including:
dialectModule), with automatic token generationand Region discovery
Testing
npm test(18 passed)npm run test:integration(5 passed); skip cleanly without credentials