Skip to content

Commit

Permalink
Fix syntax and consistently use mjs import in readme example.
Browse files Browse the repository at this point in the history
  • Loading branch information
autopulated committed Jan 29, 2024
1 parent 3aec5d6 commit 2e42715
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,44 @@

## Quickstart:
```js
const DynamoDM = require('dynamodm')();
import DynamoDM from 'dynamodm';

const table = DynamoDM.Table('my-dynamodb-table');
// get an instance of the API (options can be passed here)
const ddm = DynamoDM();

// get a reference to a DynamoDM table:
const table = ddm.Table({name: 'my-dynamodb-table'});

// Create a User model with a JSON schema:
const UserModel = table.model(DynamoDM.Schema('user', {
const UserModel = table.model(ddm.Schema('user', {
properties: {
// Identify the id field using the built-in schema. Every model in the same table must share the same id field name:
id: DynamoDM.DocIdField,
id: ddm.DocIdField,
emailAddress: {type: 'string'},
marketingComms: {type: 'boolean', default: false}
},
}));
// and a Comment model:
const CommentModel = table.model(DynamoDM.Schema('c', {
const CommentModel = table.model(ddm.Schema('c', {
properties: {
id: DynamoDM.DocIdField,
createdAt: DynamoDM.CreatedAtField,
id: ddm.DocIdField,
createdAt: ddm.CreatedAtField,
text: {type: 'string' },
user: DynamoDM.DocId
user: ddm.DocId
},
additionalProperties: true
}, index: {
findByUser: {
hashKey: 'user',
sortKey: 'createdAt'
}, {
index: {
findByUser: {
hashKey: 'user',
sortKey: 'createdAt'
}
}
}));

// wait for the table to be ready (created if necessary, creation of index):
await table.ready();


// create some documents (instances of models):
const aUser = new UserModel({emailAddress:"friend@example.com"});
await aUser.save();
Expand Down

0 comments on commit 2e42715

Please sign in to comment.