Skip to content
This repository has been archived by the owner on Apr 27, 2019. It is now read-only.

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckegg committed Mar 19, 2013
1 parent a46d97e commit c8bfb71
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var contextDB = ContextDB(db, {
item: 'items[id={.id}]',
collection: 'items',
match: {
parent_id: {$param: 'parent_id'},
parentId: {$query: 'parentId'},
type: 'comment'
},
allow: {
Expand All @@ -55,7 +55,7 @@ var contextDB = ContextDB(db, {
})
```

### contextDB.applyChange(object)
### contextDB.applyChange(object, cb)

Push objects into the database. This will also notify all relevant datasources listening.

Expand All @@ -64,14 +64,21 @@ All changes will be accepted so this should only be triggered by trusted sources
```js
var newObject = {
id: 1,
parent_id: 'site',
parentId: 'site',
name: "Home",
type: 'page'
}

contextDB.applyChange(newObject)
```

### contextDB.applyChanges(arrayOfObjects, cb)

Batch version of `applyChange`.

### contextDB.forceIndex()

Forces the database to reindex all the matchers. Could take some time depending on how many items there are in the DB. **This is automatically run if you change the `match` portion of any matcher**.

### contextDB.generate(options, callback(err, datasource))

Expand All @@ -83,7 +90,7 @@ Changes pushed in using [`datasource.pushChange`](https://github.com/mmckegg/jso

Options:

- **data**: The starting point for the datasource. Matchers can use $query to hook into the specified attributes.
- **data**: The starting point for the datasource. Matchers should use $query to hook into the specified attributes.
- **matcherRefs**: An array of refs from the matchers specified when creating the contextDB. This option is order sensitive as matchers can refer to the result of another matcher.

### datasource.emitChangesSince(timestamp)
Expand All @@ -93,7 +100,7 @@ Will cause the datasource to emit all changes to any listeners that have occured
## Example

```js
var params = {parent_id: 1, user_id: 'user_123', token: 'some_unique_random_string'}
var params = {parentId: 1, userId: 'user_123', token: 'some_unique_random_string'}
var matcherRefs = ['current_user', 'items_for_parent']

var userDatasources = {}
Expand Down

0 comments on commit c8bfb71

Please sign in to comment.