How can this code be optimized? I don't want to call where 2 times... Is it possible to have better query than this?
return self.db.clientDevices.where(device).then(function (rows) {
if (rows.length != 1) {
device.key = value;
self.db.clientDevices.insert(device).then();
} else {
self.db.clientDevices.where(device).update(device).then();
}
});