Skip to content

feat(javascript): Add Sequelize ORM sample for Aurora DSQL - #1845

Open
lasitab-code wants to merge 1 commit into
aws-samples:mainfrom
lasitab-code:add-javascript-sequelize-sample
Open

lasitab-code wants to merge 1 commit into
aws-samples:mainfrom
lasitab-code:add-javascript-sequelize-sample

Conversation

@lasitab-code

Copy link
Copy Markdown

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:

  • CRUD operations for a hotel reservation domain (guests, rooms, reservations, payments)
  • IAM authentication (admin + non-admin user flows) via the Aurora DSQL node-postgres connector (dialectModule), with automatic token generation
    and Region discovery
  • Foreign keys between the hotel entities
  • OCC retry with exponential backoff and jitter
  • Schema isolation for a least-privilege, non-admin application user
  • Unit tests (Jest) and live integration tests

Testing

  • End-to-end tested with admin and non-admin users against a live DSQL cluster (us-west-2)
  • Unit tests pass: npm test (18 passed)
  • Integration tests pass against a live cluster: npm run test:integration (5 passed); skip cleanly without credentials
  • Security scan: 0 CVEs, 0 secrets, 0 code vulnerabilities

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

@praba2210 praba2210 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three documented steps fail as written:

  1. Here — CLUSTER_REGION is "optional" per line 45 but this snippet requires it.
  2. Line 213 — FK query filters table_schema = 'public'; the recommended hotel-schema path returns 0 rows vs "Expect four foreign keys".
  3. setup_app_user.sql:38 — "run the app with CLUSTER_USER=admin" can't create the hotel tables; db.js:28-30 forces admin to public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants