I am using pg-promise.
I am having an issue trying to insert the following Javascript array:
[ { email: 'test1@gmail.com', password: 'test2' },
{ email: 'tes2t@gmx.com', password: 'test'3 },
{ email: 'test4@gmail.com', password: 'test4' },
{ email: 'test4@yahoo.com.ar', password: 'test5' }]
Using the following:
async function insertDB(data){
const cs = new pgp.helpers.ColumnSet(['email', 'password'], {table: 'users'});
console.log(data)
const query = pgp.helpers.insert(data, cs);
db.none(query)
.then(data => {
logger.info(" Query success: ", data);
})
.catch(error => {
logger.warn(" Query error: ", error);
});
}
and I get
UnhandledPromiseRejectionWarning: Error: Property 'password' doesn't exist.
**data.password = undefined**
**data[0] = { email: 'test1@gmail.com', password: 'test2' }**
How can I insert this data into my postgresdb?