Open vitaly-t opened 7 years ago
Didn't notice that sequence is for processing a dynamic sequence. Still trying to rewrite it~~~. Thank you for your suggestion. Very appreciate it🙂
BTW, could I ask you 1 question?
when I tries to do some sql, like WHERE column IN $(dynamic_array)
,
How should I to do this?
My current solutions is
function query_values (datas) {
//! sql = "... WHERE column IN $(col:raw)"
//! db.any(sql, {col: query_values(datas)});
if (datas.length === 0) {
return '(NULL)';
}
let values = {};
for (let data of datas) {
values[data.toString()] = data;
}
return pgp.helpers.values(values);
}
But seems that pgp.helper.values
method is not for this situation(?!
See my answer here: https://stackoverflow.com/questions/10720420/node-postgres-how-to-execute-where-col-in-dynamic-value-list-query
Basically, you use the WHERE column IN $(dynamic_array:csv)
syntax, passing an array of values for dynamic_array
:wink:
looking at this code: https://github.com/nthu-stage/back-end/blob/master/src/model/workshops.js
you are misusing method
sequence
. The method is there for processing infinite/dynamic sequences, it is not for handling 1-2-3 step logic, which can easily be done within task/transaction on its own.It's just quite inefficient.