Is there a good object mapper for Amazons dynamodb(through aws sdk) which can be used in nodejs?
Asked Answered
C

8

43

Maybe the question does not apply to dynamoDB due to it not being Relational Db. However, I'm looking for a good object mapper which can be used in nodejs and aws sdk to map existing model classes to dynamoDB tables. Does anyone have experience with this issue/question, or have you used such a module/library?

Casi answered 21/5, 2014 at 13:48 Comment(0)
M
38

If you are looking for schema:

If you are looking for something to throw javascript objects (even circular graphs) to:

dyngodb has experimental support for full-text search, and transactions too.

Both are based on aws-sdk.

Mathematician answered 21/5, 2014 at 20:23 Comment(0)
C
7

Also worth considering is simple marshallers, which just translate between the dynamoDB format and regular js objects or JSON.

DynamoDb-Data-Types
https://github.com/kayomarz/dynamodb-data-types
https://www.npmjs.com/package/dynamodb-data-types

"This utility helps represent AWS DynamoDb data types. It maps (marshalls) JavaScript data into the format required by DynamoDb."

dynamoDb-marshaler
https://github.com/CascadeEnergy/dynamoDb-marshaler https://www.npmjs.com/package/dynamodb-marshaler

"Translates sane javascript objects (and JSON) into DynamoDb format and vice versa." [does not support B type.]

Update 2016-06:
Just discovered that the AWS SDK now does this for you. Their documentation is only partially converted so I guess this is a recent addition. Read about it here.

But these marshallers are still useful because there are circumstances where you can't use the new document client, eg. when processing a dynamoDB stream.

Canale answered 9/5, 2016 at 17:40 Comment(2)
Thanks for your answers. I am using dynamoDB streams and currently they have to be transformed to javascript or JSON objects when they trigger my Lambda functions.Keithakeithley
Thanks for Update 2016-06, it really nice!Rick
B
7

You could also try: https://dynamoosejs.com/. It is inspired by mongoose again.

Bookkeeping answered 31/7, 2017 at 18:19 Comment(0)
E
7

If you are using Typescript, dynamo-easy might be a good option. Just add some decorators to your model and start using it.

import { Model, PartitionKey, DynamoStore } from '@shiftcoders/dynamo-easy'

@Model()
export class Person {
  @PartitionKey()
  id: string
  name: string
  yearOfBirth: number
}

const personStore = new DynamoStore(Person)

personStore
  .scan()
  .whereAttribute('yearOfBirth').equals(1958)
  .exec()
  .then(res => console.log('ALL items with yearOfBirth == 1958', res))

It uses the AWS DynamoDB sdk but takes care of the mapping between JS and DynamoDB types and provides a simple to use fluent API.

full disclosure: I am one of the authors of this library

Eligibility answered 28/2, 2019 at 6:41 Comment(0)
F
1

After looking over all the posts I landed on https://github.com/awspilot/dynamodb-oop

It doesn't hide the API but instead just wraps it in a nice, fluent way with promises even and you inject your version of the aws-sdk. It's similar to dynamodb-data-types but also wraps the methods too (not just the data types).

Extra bonus, the same author has https://github.com/awspilot/dynamodb-sql Didn't use the sql wrapper but I can see how some people may prefer that.

Dynamoose is obviously inspired by mongoose and is a good choice if you have a well-defined schema and/or want to be abstracted away from the DynamoDB details.

Falito answered 12/12, 2017 at 8:32 Comment(0)
V
0

Have you seen dynasaur? It seems to be the type of thing you're looking for, but I have not used it myself. There's also dynamodb-data-types which is not an ORM, but makes it easy to convert to/from standard JavaScript objects.

Vikki answered 21/5, 2014 at 16:52 Comment(0)
B
0

I'd recommend you check out Dynamode, a DynamoDB client I created last year. It's designed to work flawlessly with Typescript. It integrates nicely with Node.js and AWS SDK, and it might be just what you're looking for. Give it a spin!

Babylonian answered 15/2 at 8:42 Comment(0)
M
0

Electrodb is a great tool that adheres to the single table design philosophy. You can model your data with it and the library manages all data storage while you can focus on developing your app

Mccully answered 2/4 at 3:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.