Skip to content

Commit

Permalink
Add save/saveSync method to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CreaturePhil committed Jun 16, 2015
1 parent 2ace0d7 commit 1d65b03
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ For each DBB's method, there is a synchronous version of it. For example, `get`
* [`insertSync`](#insertSync)
* [`remove`](#remove)
* [`removeSync`](#removeSync)
* [`save`](#save)
* [`saveSync`](#saveSync)

<a name="create" />
### Create Database
Expand Down Expand Up @@ -445,6 +447,48 @@ db().removeSync('key');
db('users').removeSync({name: 'Phil'});
```

<a name="save" />
### save(document, [callback])

Save a document in the database.

__Arguments__

1. `document` (*): Usually an object.
2. `callback(err)` (Function): *Optional* A callback which is called when
writing to the JSON file has finished, or an error occurs.

__Examples__

```js
db('users').find({name: 'phil'}, function(err, user) {
if (err) throw err;
user.money++;
user.emails.push('hello@gmail.com');
user.posts = [];
db('users').save(user, function(err) {
if (err) throw err;
});
});
```

<a name="saveSync" />
### saveSync(document)

Synchronous `save`. Returns undefined.

__Arguments__

1. `document` (*): Usually an object.

__Examples__

```js
var user = db('users').find({name: 'phil'});
user.name = 'jack';
db('users').save(user);
```

<a name="limits" />
## Limits

Expand Down

0 comments on commit 1d65b03

Please sign in to comment.