Skip to content

Commit

Permalink
- changed data result from null to an empty array when flags are many…
Browse files Browse the repository at this point in the history
… + none.

- docs update.
  • Loading branch information
Vitaly Tomilov committed Mar 6, 2015
1 parent 1f24b3a commit a185b1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ db.manyOrNone("select * from users")
Each query function resolves <b>data</b> according to the <b>Query Result Mask</b> that was used, and must be handled accordingly, as explained below.
* `none` - <b>data</b> is `null`. If the query returns any kind of data, it is rejected.
* `one` - <b>data</b> is a single object. If the query returns no data or more than one row of data, it is rejected.
* `many` - <b>data</b> is an array of objects. If the query returns no data, it is rejected.
* `many` - <b>data</b> is an array of objects. If the query returns no rows, it is rejected.
* `one` | `none` - <b>data</b> is `null`, if no data was returned; or a single object, if there was one row of data returned. If the query returns more than one row of data, the query is rejected.
* `many` | `none` - <b>data</b> is `null`, if no data was returned. If there were one or more rows returned, data is an array of objects.
* `many` | `none` - <b>data</b> is an array of objects. When no rows returned, `data` is an empty array.

If you try to specify `one` | `many` in the same query, such query will be rejected without executing it, telling you that such mask is not valid.

Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ queryResult = {
module.exports = function (options) {

var lib = function (cn) {
if(!$isEmptyObject(this)){
if (!$isEmptyObject(this)) {
// This makes it easy to locate the most common mistake -
// skipping keyword 'new' when calling: var db = new pgp(cn);
throw new Error("Invalid database object instantiation.");
Expand Down Expand Up @@ -191,7 +191,7 @@ function dbInit(dbInst, cn, options) {

var tx = this;

if(!$isEmptyObject(tx)){
if (!$isEmptyObject(tx)) {
// This makes it easy to locate the most common mistake -
// skipping keyword 'new' when calling: var tx = new db.tx(cn);
throw new Error("Invalid transaction object instantiation.");
Expand Down Expand Up @@ -321,7 +321,7 @@ function $isNull(val) {
}

// Checks if the object is empty (has no properties);
function $isEmptyObject(obj){
function $isEmptyObject(obj) {
return Object.keys(obj).length === 0;
}

Expand Down Expand Up @@ -398,7 +398,7 @@ function $query(client, query, qrm) {
}
} else {
if (qrm & queryResult.none) {
data = null;
data = (qrm & queryResult.many) ? [] : null;
} else {
reject("No rows returned from query: '" + query + "'");
}
Expand Down

0 comments on commit a185b1a

Please sign in to comment.