-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrealm-search.js
47 lines (39 loc) · 1.01 KB
/
realm-search.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* eslint-disable prettier/prettier */
import Realm from 'realm';
import RNFS from 'react-native-fs';
const realmFile = 'sttmdesktop-evergreen-v2.realm';
const schemaFile = 'realm-schema-evergreen.json';
const realmPath = RNFS.DocumentDirectoryPath + `/${realmFile}`;
const realmSchema = RNFS.DocumentDirectoryPath + `/${schemaFile}`;
const realmConfig = {
path: realmPath,
schema: realmSchema.schemas,
schemaVersion: realmSchema.schemaVersion,
};
let initialized = false;
const init = () => {
try {
initialized = true;
} catch (e) {
initialized = false;
}
};
const loadAng = (PageNo, SourceID = 'G') =>
new Promise((resolve, reject) => {
if (!initialized) {
init();
}
Realm.open(realmConfig)
.then(realm => {
const rows = realm.objects('Verse').filtered('PageNo = $0 AND Source.SourceID = $1', PageNo, SourceID);
if (rows.length > 0) {
resolve(rows);
} else {
reject();
}
})
.catch(reject);
});
export {
loadAng,
};