1602/jugglingdb — pull request #305 by coderbuzz (2013-07-12 07:55:10+00:00)
Title: Extend findOrCreate() query param behavior

In real world, the most common use of findOrCreate() is to simplify steps of getting a record or insert new if doesn't exist.

I propose to change query 'data' structure: remove 'query' key, so it's value is the query it self because:
1. Find will always a WHERE statement, no else.
2. This will simplify typo usage.
3. The where values mostly part of required data. So it is good to include where values as 'data' to be inserted if the data not exist.

Example usage:
```javascript
function setData(key, value) {
if (typeof value === 'object')
value = JSON.stringify(value);

// { key: key } is our where expression
// In most cases the where keys is required, so query will merged to data as new data = { key: key, value: value } to automatically insert later if the data not exists.

Data.findOrCreate({ key: key }, { value: value },
function (err, record, created) {

if (!created) {
console.log('UPDATING EXISTING RECORD');

record.value = value;
record.save(function (err, record) {
console.log(err, record);
});
} else console.log('NEW RECORD INSERTED');
});
}

setData('theKey', { name: 'A Name', date: new Date });
setData('another_Key', 'String Data');
setData('another_Key', 10000);
```