Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created documentation for query and queryRecord #156

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 on [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