I am using pgp.helpers.insert to save data into PostgreSQL which is working well. However, I need to return values to present in a response. I am using:
this.collection.one(this.collection.$config.pgp.helpers.insert(values, null, 'branch'))
which returns no data.
What I want to be able to do is return the branch id after a successful insert, such as:
INSERT into branch (columns) VALUES (values) RETURNING pk_branchID
Simply append the
RETURNING...
clause to the generated query:You must have a large object there if you want to automatically generate the insert. Namespace helpers is mostly valued when generating multi-row inserts/updates, in which case a ColumnSet is used as a static variable:
Note that in this case we do .many, as 1 or more rows/results are expected back. This can even be transformed into just an array of id-s:
see: Database.map