Files
old-naida/helpfunctions/addobject.js
2019-10-31 01:11:25 +01:00

26 lines
731 B
JavaScript

//Checking if object existis in DB table objects
//if no inserts new object (implicitly)
const handleAddObject = (reqobjname, db) => {
db.transaction (trx => {
trx.select('objname')
.from('objects')
.where('objname', 'ilike', reqobjname)
.then ( data => {
if (data.length===0) {
return trx('objects')
.returning('*')
.insert( {
objname: reqobjname
})
.then(obj => {
console.log('Inserted new object implicitly.');
})
}
})
.then(trx.commit)
.catch(trx.rollback)
})
}
module.exports = {
handleAddObject
}