diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-10-30 21:14:02 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-10-30 21:14:02 +0100 |
commit | ee4c698e03145b6cad2ed916b1b9249f910845cd (patch) | |
tree | 792ed71c24625fb82f81450547c7eec2029c16fa | |
parent | a949af38a33cd08577ab91d6c5eb418520daefc8 (diff) | |
download | diller-server-ee4c698e03145b6cad2ed916b1b9249f910845cd.tar.gz diller-server-ee4c698e03145b6cad2ed916b1b9249f910845cd.tar.bz2 diller-server-ee4c698e03145b6cad2ed916b1b9249f910845cd.tar.xz diller-server-ee4c698e03145b6cad2ed916b1b9249f910845cd.zip |
core:
o Using manyOrNone on SELECTs that can return an empty result set.
-rw-r--r-- | src/DillerDao.js | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/DillerDao.js b/src/DillerDao.js index 3a6601f..cae80d7 100644 --- a/src/DillerDao.js +++ b/src/DillerDao.js @@ -9,11 +9,11 @@ function DillerDao(tx) { // ------------------------------------------------------------------------------------------------------------------- function devices() { - return tx.many("SELECT " + deviceColumns + " FROM device"); + return tx.manyOrNone("SELECT " + deviceColumns + " FROM device"); } function deviceById(id) { - return tx.oneOrNone("SELECT " + deviceColumns + " FROM device WHERE id=$1", id); + return tx.one("SELECT " + deviceColumns + " FROM device WHERE id=$1", id); } function deviceByKey(key) { @@ -37,7 +37,7 @@ function DillerDao(tx) { } function devicePropertiesByDeviceId(deviceId) { - return tx.many('SELECT ' + propertyColumns + ' FROM device_property WHERE device=$1', [deviceId]); + return tx.manyOrNone('SELECT ' + propertyColumns + ' FROM device_property WHERE device=$1', [deviceId]); } function insertDeviceProperty(deviceId, key) { @@ -58,7 +58,7 @@ function DillerDao(tx) { function valuesByPropertyId(propertyId, limit) { limit = limit || 10; - return tx.many('SELECT timestamp, coalesce(value_numeric::text, value_text) AS value FROM value WHERE property=$1 ORDER BY timestamp DESC LIMIT $2', [propertyId, limit]); + return tx.manyOrNone('SELECT timestamp, coalesce(value_numeric::text, value_text) AS value FROM value WHERE property=$1 ORDER BY timestamp DESC LIMIT $2', [propertyId, limit]); } function insertValue(propertyId, value) { |