From 8e9e69a0e1d96cb63608c8b0bda02d59ac1a292b Mon Sep 17 00:00:00 2001 From: Kam Lasater Date: Wed, 21 Jun 2023 20:14:41 -0400 Subject: [PATCH] fix: updated examples --- README.md | 32 ++++++++++++++++++++++++++++---- test/instantiate.test.js | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a57948d..af04170 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,41 @@ Together with the Cyclic.sh DynamoDB indexing strategy and data model, the SDK s > Credentials are required only for connecting to the database from local and expire after one hour, don't add them to an environment configuration. -3. Set the database name as an environment variable before requiring the SDK - this can be added to environment configurations. +3. Set the database name as an environment variable before requiring the SDK - this can be added to environment configurations. + + ```js + process.env.CYCLIC_DB = 'your-url-subdomainCyclicDB' + import db from '@cyclic.sh/dynamodb' + ``` ```js process.env.CYCLIC_DB = 'your-url-subdomainCyclicDB' const db = require('@cyclic.sh/dynamodb') ``` ---------- -# Example +## ESM or CJS + +You can use either esm or cjs imports. Any of the below examples can be altered with the import type of you choice. + +### ESM +```js +// example.mjs +import CyclicDB from '@cyclic.sh/dynamodb' +const db = CyclicDB('your-table-name') +``` + +### CommonJS + +```js +// example.cjs +const CyclicDB = require('@cyclic.sh/dynamodb') +const db = CyclicDB('your-table-name') +``` + +# Examples ```js -// example.js +// example.cjs const CyclicDB = require('@cyclic.sh/dynamodb') const db = CyclicDB('your-table-name') @@ -113,7 +137,7 @@ The TTL setting passes through to the [DynamoDB TTL](https://docs.aws.amazon.com ## Example ```js -// example.js +// example.cjs const CyclicDB = require('@cyclic.sh/dynamodb') const db = CyclicDB('your-table-name') diff --git a/test/instantiate.test.js b/test/instantiate.test.js index 00f5e70..66f88c7 100644 --- a/test/instantiate.test.js +++ b/test/instantiate.test.js @@ -3,7 +3,7 @@ process.env.AWS_REGION = process.env.AWS_REGION || "us-east-2"; // import { CyclicDb } from "../src"; import db_import from "../src"; -describe("require('CyclicDb')", () => { +describe("import db from ../src", () => { test("can be used as an object relying on env vars ", async () => { const db = db_import;