I am using nexus for my database purpose but I have a question which also generally applicable to JS/TS.
knex('cars').insert(cars).then(() => console.log("data inserted"))
.catch((err) => { console.log(err); throw err })
.finally(() => {
knex.destroy();
});
How can I create the above as a new Promise with reject or resolve to look like this
byID(id: string): Promise<TEntity> {
return new Promise((resolve, reject) => {
const result = pg(cars)
.where({ 'id': id })
// .andWhere('age', '<', 18);
.first();
if (!result)
return reject(new ModelNotFoundError('LMAO user not found'));
resolve(result)
})
}