Skip to content

Commit

Permalink
create documentation form query and queryRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardTolosajr committed Oct 21, 2016
1 parent 7ccd2ad commit be0a9e0
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,103 @@ export default Ember.Route.extend({
});
```

### Query and QueryRecord

query and queryRecord is relying over [pouchdb-find](https://github.com/nolanlawson/pouchdb-find)

### db.createIndex(index [, callback])

Create an index if it doesn't exist.

```javascript
// app/adapters/application.js
function createDb() {
...

db.createIndex({
index: {
fields: ['data.name']
}
}).then((result) => {
// {'result': 'created'} index was created
});

return db;
};
```

### store.query(model, options)

Find all docs where doc.name === 'Mario'

```javascript
// app/routes/smasher/index.js
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.query('smasher', {
filter: { name: 'Mario' }
});
}
});
```

Find all docs where doc.name === 'Mario' and doc.debut > 1990:

```javascript
// app/routes/smasher/index.js
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.query('smasher', {
filter: {
name: 'Mario'
debut: { $gt: 1990 }
}
});
}
});
```

Sorted by doc.debut descending.

```javascript
// app/routes/smasher/index.js
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.query('smasher', {
filter: {
name: 'Mario'
sort: [
{ debut: 'desc' }
]
}
})
}
});
```

### store.queryRecord(model, options)

Find one document where doc.name === 'Mario'

```javascript
// app/routes/smasher/index.js
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.queryRecord('smasher', {
filter: { name: 'Mario' }
});
}
});
```

## Attachments

`Ember-Pouch` provides an `attachment` transform for your models, which makes working with attachments as simple as working with any other field.
Expand Down

0 comments on commit be0a9e0

Please sign in to comment.