小编wiz*_*ard的帖子

Node.js - PostgreSQL - 无法确定参数 $1 错误的数据类型

我正在尝试使用 node.js npm 包创建 PostgreSQL 准备好的语句pg。但是,我不断收到错误:

无法确定参数 $1 的数据类型

 function promiseQuery(sql, values) {
    return new Promise(function(resolve, reject) {
        pool.query('select $1 from workers', ['name'], function(err, result) {
            if (err) {console.log(err); reject(err)}
            else resolve(result.rows);   
        })
    });
}
Run Code Online (Sandbox Code Playgroud)

在数据库中,该name字段设置为 type text not null

我也尝试了pg-promise,但也没有成功。

javascript postgresql node.js pg pg-promise

7
推荐指数
1
解决办法
1万
查看次数

使用带有promise的forEach(),而访问前一个promise会导致.then()链?

我有承诺的以下功能:

const ajaxRequest = (url) => {
  return new Promise(function(resolve, reject) {
    axios.get(url)
      .then((response) => {
        //console.log(response);
        resolve(response);
      })
      .catch((error) => {
        //console.log(error);
        reject();
      });
  });
}


const xmlParser = (xml) => {
  let { data } = xml;
  return new Promise(function(resolve, reject) {
    let parser = new DOMParser();
    let xmlDoc = parser.parseFromString(data,"text/xml");

    if (xmlDoc.getElementsByTagName("AdTitle").length > 0) {
      let string = xmlDoc.getElementsByTagName("AdTitle")[0].childNodes[0].nodeValue;
      resolve(string);
    } else {
      reject();
    }
  });
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试为JSON数组中的每个对象应用这些函数:

const array = [{"id": 1, "url": "www.link1.com"}, {"id": 1, …
Run Code Online (Sandbox Code Playgroud)

javascript scope promise ecmascript-6 es6-promise

7
推荐指数
1
解决办法
993
查看次数

使用postgres和sequelize-mock进行单元测试模拟

我正在尝试使用sequelize-mock,node和postgres进行单元测试,但是无论何时我对我的模拟进行查询,无论是否在模拟中获取了当前数据,我都会得到结果。看来sequelize-mock是根据我的查询自动生成的结果。我试图用autoQueryFallback选项,但我发现了SequelizeMockEmptyQueryQueueError

例如:

describe('/GET/:email/exists', () => {
  it('it should check if email exists - it should fail', async () => {
    const email = 'somemail@mail.com';
    try {
      const res = await fakeDbUtil.isEmailExistsDb(email);
      chai.assert.equal(res, null);
    } catch(e) {
      console.log(e);
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

我的模拟数据库中没有给定的电子邮件,因此我希望得到null结果。但是,我得到的结果包含我的模拟信息以及当前电子邮件(覆盖我的模拟原始电子邮件)。

我不确定我做错了什么吗? 还有其他一些可以与postgres和续集一起使用的良好模拟框架吗?

postgresql unit-testing mocking node.js sequelize.js

5
推荐指数
1
解决办法
1031
查看次数

mysql数据透视表日期(垂直于水平数据)

我一直在搜索没有得体的答案.

我想转换这个表:


Client_id    Date
-----------  ------------  
1            2013-02-03    
1            2013-02-10
1            2013-05-12
2            2013-02-03
2            2013-07-15
Run Code Online (Sandbox Code Playgroud)

至:


Client_id    Date1          Date2         Date3         Date4, Date5, Date6...
-----------  ------------   ------------  ------------  ------------
1            2013-02-03     2013-02-10    2013-05-12
2            2013-02-03     2013-07-15
Run Code Online (Sandbox Code Playgroud)

mysql sql pivot

3
推荐指数
1
解决办法
7877
查看次数

Node.js:异步回调 vs 同步回调 vs process.nextTick vs setTimeout

不久前我开始使用node.js进行开发。最近,我深入 研究了节点的“事件循环”和异步机制。但我仍然不完全理解同步和异步回调之间的区别。

在这个来自node.js API的示例中,我理解为什么不清楚首先调用哪个函数。

maybeSync(true, () => {
  foo();
});
bar();
Run Code Online (Sandbox Code Playgroud)

但是,如果我们有:

syncOrAsync(arg, () => {
 if (arg) {
   cb(arg);
   return;
 }
});

syncOrAsync(true, function(result) {
  console.log('result');
});

console.log('after result);
Run Code Online (Sandbox Code Playgroud)

我不清楚为什么它们总是按同步顺序执行,尽管我做了一个回调函数,该函数应该在堆栈为空由事件循环执行( console.log('after result') 完成)。我是否总是需要添加 process.nextTick(cb);才能实现异步?process.nextTick 和 process.nextTick 之间有什么区别setTimeout();

javascript asynchronous callback node.js

3
推荐指数
1
解决办法
1165
查看次数

获取复选框值而不刷新页面

我有一张复选框:

<td><input id="box" name="box" type="checkbox" value="1" checked /></td>
<td><input id="box" name="box" type="checkbox" value="2" checked /></td>
<td><input id="box" name="box" type="checkbox" value="3" checked /></td>
Run Code Online (Sandbox Code Playgroud)

我想在选中或取消选中复选框时提交复选框值(每次一个)而不刷新页面:

if (isset($_GET['box'])) {
   echo "Success!"
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我得到了这个javascript代码来检查框是否已选中或未选中:

function validate(){ 
if (document.getElementById('box').checked){
    alert("checked") ;
}else{
    alert("You didn't check it! Let me check it for you.")
}
}
Run Code Online (Sandbox Code Playgroud)

我想在其上添加AJAX,但到目前为止我尝试的所有代码段代码都不适合我的代码.我会感谢你的帮助.

html javascript php ajax get

0
推荐指数
1
解决办法
5921
查看次数