Skip to content

Commit

Permalink
Add changelog and update readme example code.
Browse files Browse the repository at this point in the history
  • Loading branch information
autopulated committed Jan 30, 2024
1 parent 7107c8b commit 3fb2ba4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### 1.0.2
* Fix asynchronous promise handling in queryMany.
* Removed remains of deprecated query APIs from earlier development.

### 1.0.1
* Updated readme and example code.

# 1.0.0
Initial public release.
36 changes: 19 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,51 @@ import DynamoDM from 'dynamodm';
// get an instance of the API (options can be passed here)
const ddm = DynamoDM();

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

// Create a User model with a JSON schema:
const UserModel = table.model(ddm.Schema('user', {
// Create User and Comment models with their JSON schemas in this table:
const UserSchema = 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: ddm.DocIdField,
emailAddress: {type: 'string'},
marketingComms: {type: 'boolean', default: false}
},
}));
// and a Comment model:
const CommentModel = table.model(ddm.Schema('c', {
});

const CommentSchema = ddm.Schema('c', {
properties: {
id: ddm.DocIdField,
createdAt: ddm.CreatedAtField,
text: {type: 'string' },
user: ddm.DocId
user: ddm.DocId,
// identify a field to be used as the creation timestamp using a
// built-in schema:
createdAt: ddm.CreatedAtField
},
additionalProperties: true
}, {
// The schema also defines the indexes (GSI) that this model needs:
index: {
findByUser: {
hashKey: 'user',
sortKey: 'createdAt'
}
}
}));
})

const User = table.model(UserSchema);
const Comment = table.model(CommentSchema);

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

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

const aComment = new CommentModel({user: aUser.id, text: "My first comment."});
const aComment = new Comment({ user: aUser.id, text: "My first comment." });
await aComment.save();

// query for some documents:
const commentsForUser = await CommentModel.queryMany({user: aUser.id});

const commentsForUser = await Comment.queryMany({ user: aUser.id });
```

## Philosophy
Expand Down

0 comments on commit 3fb2ba4

Please sign in to comment.