在 simpledb 中运行 select 并使用 node.js 给出错误

发布于 2024-11-04 17:56:36 字数 1167 浏览 3 评论 0原文

我正在运行以下代码: https://github.com/rjrodger/simpledb

var simpledb = require('simpledb');
var sys = require('sys');
sdb  = new simpledb.SimpleDB({keyid:'kye'
                    ,secret:'mysectkey'});
var str="select  *  from youngib where createdon is not null  order by createdon desc limit 10";                    
sdb.select (str,  function( error, result ) {
        console.log('attr1 = '+sys.inspect(error));
        console.log('result = '+sys.inspect(result));
    });

如果我在单独的文件中运行它,它就会运行,但如果我在我的项目中运行它给了我这个错误,为什么会出现这个错误?

{ Code: 'SignatureDoesNotMatch',
  Message: 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.' } 

问题是我已经声明

Array.prototype.in_array = function(p_val) {
    for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == p_val) {
            return true;
        }
    }
    return false;
}

由于这个原因它没有执行 simpledb ,我不知道为什么,如果你知道请告诉我。

I am running following code :
https://github.com/rjrodger/simpledb

var simpledb = require('simpledb');
var sys = require('sys');
sdb  = new simpledb.SimpleDB({keyid:'kye'
                    ,secret:'mysectkey'});
var str="select  *  from youngib where createdon is not null  order by createdon desc limit 10";                    
sdb.select (str,  function( error, result ) {
        console.log('attr1 = '+sys.inspect(error));
        console.log('result = '+sys.inspect(result));
    });

if i run this in seperate file it run but if i run in my project it gives me this error ,why this error coming?

{ Code: 'SignatureDoesNotMatch',
  Message: 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.' } 

the problem was that there i have declare

Array.prototype.in_array = function(p_val) {
    for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == p_val) {
            return true;
        }
    }
    return false;
}

due to this it was not executing the simpledb , i don't know why, if you know please tell me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女中豪杰 2024-11-11 17:56:36

如果扩展 Array.prototype ,您可能会遇到 for ... in 循环问题。

例如:

Array.prototype.foo = 42;
var array = [1,2,3];
for (var index in array) {
    console.log(index + "," + array[index]);
    // logs 0,1 1,2 2,3 foo,42
}

for in 循环迭代所有属性。因此,基本上,您的第 3 方代码假设您没有在 Array.prototype 上进行扩展。

由于这些原因,扩展本机原型是不好的做法。

至于您的 in_array 方法,您可以

var contains = someArray.some(function(val) {
    return val === p_val;
});

改为使用。

If you extend Array.prototype you can get issues with for ... in loops.

For example:

Array.prototype.foo = 42;
var array = [1,2,3];
for (var index in array) {
    console.log(index + "," + array[index]);
    // logs 0,1 1,2 2,3 foo,42
}

The for in loop iterates over all properties. So basically your 3rd party code makes the assumption you have not extend on Array.prototype.

Extending native prototypes is bad practice for these reasons.

As for your in_array method you could use

var contains = someArray.some(function(val) {
    return val === p_val;
});

instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文