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

Create Pouch Service #172

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions addon/adapters/pouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,13 @@ export default DS.RESTAdapter.extend({
var recordTypeName = this.getRecordTypeName(type);
var db = this.get('db');

var queryParams = {
selector: this._buildSelector(query.filter)
};

if (!Ember.isEmpty(query.sort)) {
queryParams.sort = this._buildSort(query.sort);
query.sort = this._buildSort(query.sort);
}

return db.find(queryParams).then(pouchRes => db.rel.parseRelDocs(recordTypeName, pouchRes.docs));
return db.find(query).then(pouchRes => {
return db.rel.parseRelDocs(recordTypeName, pouchRes.docs)
});
},

queryRecord: function(store, type, query) {
Expand Down
27 changes: 2 additions & 25 deletions blueprints/pouch-adapter/files/__root__/adapters/__name__.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import { Adapter } from 'ember-pouch';
import PouchDB from 'pouchdb';
import config from '<%= dasherizedPackageName %>/config/environment';
import Ember from 'ember';

const { assert, isEmpty } = Ember;

function createDb() {
let localDb = config.emberPouch.localDb;

assert('emberPouch.localDb must be set', !isEmpty(localDb));

let db = new PouchDB(localDb);

if (config.emberPouch.remoteDb) {
let remoteDb = new PouchDB(config.emberPouch.remoteDb);

db.sync(remoteDb, {
live: true,
retry: true
});
}

return db;
}

export default Adapter.extend({
pouch:Ember.inject.service(),
init() {
this._super(...arguments);
this.set('db', createDb());
this.set('db', this.get('pouch.db'));
}
});
29 changes: 29 additions & 0 deletions blueprints/pouch-adapter/files/__root__/services/pouch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Ember from 'ember';
import PouchDB from 'pouchdb';
import config from '<%= dasherizedPackageName %>/config/environment';
const { assert, isEmpty } = Ember;

export default Ember.Service.extend({
db:null,
init(){
this._super(...arguments);
this.setup();
},
setup(){
let localDb = config.emberPouch.localDb;

assert('emberPouch.localDb must be set', !isEmpty(localDb));

let db = new PouchDB(localDb);

if (config.emberPouch.remoteDb) {
let remoteDb = new PouchDB(config.emberPouch.remoteDb);

db.sync(remoteDb, {
live: true,
retry: true
});
}
this.set('db',db);
}
});