简体   繁体   English

Amazons dynamodb(通过aws sdk)有一个很好的对象映射器可以在nodejs中使用吗?

[英]Is there a good object mapper for Amazons dynamodb(through aws sdk) which can be used in nodejs?

Maybe the question does not apply to dynamoDB due to it not being Relational Db. 也许这个问题不适用于dynamoDB,因为它不是关系型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. 但是,我正在寻找一个好的对象映射器,它可以在nodejs和aws sdk中用于将现有的模型类映射到dynamoDB表。 Does anyone have experience with this issue/question, or have you used such a module/library? 有没有人有这个问题/问题的经验,或者您是否使用过这样的模块/库?

If you are looking for schema: 如果您正在寻找架构:

If you are looking for something to throw javascript objects (even circular graphs) to: 如果您正在寻找将javascript对象(甚至是圆形图形)抛出到的东西:

dyngodb has experimental support for full-text search, and transactions too. dyngodb也支持全文搜索和交易

Both are based on aws-sdk. 两者都基于aws-sdk。

Also worth considering is simple marshallers, which just translate between the dynamoDB format and regular js objects or JSON. 另外值得考虑的是简单的marshallers,它只是在dynamoDB格式和常规js对象或JSON之间进行转换。

DynamoDb-Data-Types DynamoDb-数据类型
https://github.com/kayomarz/dynamodb-data-types https://github.com/kayomarz/dynamodb-data-types
https://www.npmjs.com/package/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." “此实用程序有助于表示AWS DynamoDb数据类型。它将JavaScript数据映射(marshalls)为DynamoDb所需的格式。”

dynamoDb-marshaler dynamoDb-封送
https://github.com/CascadeEnergy/dynamoDb-marshaler https://www.npmjs.com/package/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." “将理智的javascript对象(和JSON)转换为DynamoDb格式,反之亦然。” [does not support B type.] [不支持B类型。]

Update 2016-06 : 2016-06更新
Just discovered that the AWS SDK now does this for you. 刚发现AWS SDK现在为您执行此操作。 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. 但是这些marshallers仍然有用,因为在某些情况下你不能使用新的文档客户端,例如。 when processing a dynamoDB stream. 处理dynamoDB流时。

You could also try: https://dynamoosejs.com/ . 您也可以尝试: https//dynamoosejs.com/ It is inspired by mongoose again. 它再次受到猫鼬的启发。

If you are using Typescript, dynamo-easy might be a good option. 如果您使用的是Typescript,则dynamo-easy可能是一个不错的选择。 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. 它使用AWS DynamoDB sdk,但负责JS和DynamoDB类型之间的映射,并提供简单易用的流畅API。

full disclosure: I am one of the authors of this library 完全披露:我是这个图书馆的作者之一

After looking over all the posts I landed on https://github.com/awspilot/dynamodb-oop 查看了所有帖子后,我登陆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. 它不会隐藏API,而只是以一种漂亮,流畅的方式包装它甚至承诺你注入你的版本的aws-sdk。 It's similar to dynamodb-data-types but also wraps the methods too (not just the data types). 它类似于dynamodb-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. 额外的奖金,同一作者有https://github.com/awspilot/dynamodb-sql没有使用sql包装,但我可以看到一些人可能更喜欢这样。

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. Dynamoose显然受到了猫鼬的启发,如果你有一个明确定义的架构和/或想要从DynamoDB细节中抽象出来,那么它是一个很好的选择。

Have you seen dynasaur ? 你见过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. 还有dynamodb-data-types ,它不是ORM,但可以很容易地转换为标准JavaScript对象/从标准Ja​​vaScript对象转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM