我正在尝试使用 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,但也没有成功。
我有承诺的以下功能:
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) 我正在尝试使用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和续集一起使用的良好模拟框架吗?
我一直在搜索没有得体的答案.
我想转换这个表:
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) 不久前我开始使用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();?
我有一张复选框:
<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,但到目前为止我尝试的所有代码段代码都不适合我的代码.我会感谢你的帮助.
javascript ×4
node.js ×3
postgresql ×2
ajax ×1
asynchronous ×1
callback ×1
ecmascript-6 ×1
es6-promise ×1
get ×1
html ×1
mocking ×1
mysql ×1
pg ×1
pg-promise ×1
php ×1
pivot ×1
promise ×1
scope ×1
sequelize.js ×1
sql ×1
unit-testing ×1