【问题标题】:Vogels DynamoDB error to migrate to newer apiVogels DynamoDB 错误迁移到较新的 api
【发布时间】:2017-05-09 18:49:51
【问题描述】:

我正在为 node.js 使用 Vogels DynamoDB 数据映射器 - 并且一直很难在 DynamoDB(在 AWS 上)中工作。对于 DynamoDB 本地存在 NO 问题 - 它设置了架构并在 node.js 应用程序中完美运行。

但是,在部署到 AWS 时 - 出现以下错误:

Details:Error: define no longer accepts schema callback, migrate to new api

问题是我使用的是最新版本的 Vogels (https://github.com/ryanfitz/vogels)

那么为什么要迁移到新的 api 呢?

【问题讨论】:

    标签: amazon-dynamodb vogels


    【解决方案1】:

    define 中的callback 在 Vogels 2.0 中被删除: https://github.com/ryanfitz/vogels/commit/6d5e70e4fdcfd5f28058298bc63cf749d15837a9

    define 中的第二个参数现在是模式。如果您将函数作为第二个参数传递,则会收到此错误,因为 Vogel 认为您正在尝试使用 Vogels 1.x:

    if(_.isFunction(config)) {
      throw new Error('define no longer accepts schema callback, migrate to new api');
    }
    

    来源:https://github.com/ryanfitz/vogels/commit/6d5e70e4fdcfd5f28058298bc63cf749d15837a9#diff-6d186b954a58d5bb740f73d84fe39073R121

    所以请检查您的define 调用中的第二个参数。那应该是 JSON 格式的模式,而不是函数。来自官方文档的示例:

    var Account = vogels.define('Account', {
      hashKey : 'email',
    
      // add the timestamp attributes (updatedAt, createdAt)
      timestamps : true,
    
      schema : {
        email   : Joi.string().email(),
        name    : Joi.string(),
        age     : Joi.number(),
        roles   : vogels.types.stringSet(),
        settings : {
          nickname      : Joi.string(),
          acceptedTerms : Joi.boolean().default(false)
        }
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-30
      • 1970-01-01
      • 2016-05-22
      • 1970-01-01
      • 2020-03-01
      • 1970-01-01
      相关资源
      最近更新 更多