Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

express - How to execute a unnest array in a columnSet with pgpromise?

I was wondering if there was a way to call the ability to unnest an array utilizing a columnSet with PG Promise? So for example, I have a req.body call to a textfield that is split by commas on javascript back end. For example:

var juneDates = req.body.junedates.split(',')

But I can't seem to figure out how to utilize a columnSet to utilize Postgres unnest feature. This is what I have:

const cs = new pgp.helpers.ColumnSet(
    [
      {
        name: "attrib_id",
      },
      {
        name: "value",
        skip(col) {
          return col.value === null || col.value === undefined;
        },
      },
      {
        name: "response_id",
      },
    ],
    {
      table: "formquestionresponse",
    }
  );

var juneDates = req.body.junedates.split(',')

values = {
attrib_id: 1,
value: juneDates;
response_id: 2
}

const query = pgp.helpers.insert(values, cs);
      const recordsResponse = db.none(query);

I can't get the skip functionality to work either, but I know that's due to it only working on a update call. Is there anyway to do a skip for a insert or do I have to utilize JS to do that?

Thank you so much.

question from:https://stackoverflow.com/questions/66051077/how-to-execute-a-unnest-array-in-a-columnset-with-pgpromise

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...