master
 1import Realm from 'realm';
 2import Account from './account';
 3
 4export default class Repository {
 5  constructor() {
 6    this.realm = new Realm({
 7      schema: [Account]
 8    });
 9  }
10
11  all(type) {
12    return this.realm.objects(type);
13  }
14
15  count(type) {
16    return this.all(type).length;
17  }
18
19  save(type, attributes) {
20    this.realm.write(() => {
21      this.realm.create(type, attributes);
22    });
23  }
24
25  deleteAll(type){
26    this.realm.write(() => {
27      this.realm.delete(this.all(type));
28    });
29  }
30}