summaryrefslogtreecommitdiff
path: root/app/domain/repository.js
blob: 8aff970516071a104aaa804dca99b73b43c884ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Realm from 'realm';
import Account from './account';

export default class Repository {
  constructor() {
    this.realm = new Realm({
      schema: [Account]
    });
  }

  all(type) {
    return this.realm.objects(type);
  }

  count(type) {
    return this.all(type).length;
  }

  save(type, attributes) {
    this.realm.write(() => {
      this.realm.create(type, attributes);
    });
  }

  deleteAll(type){
    this.realm.write(() => {
      this.realm.delete(this.all(type));
    });
  }
}