-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbHelper.js
More file actions
58 lines (50 loc) · 1.39 KB
/
dbHelper.js
File metadata and controls
58 lines (50 loc) · 1.39 KB
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
48
49
50
51
52
53
54
55
56
57
58
import Loki from 'lokijs';
let db = null;
export function databaseInitialize() {
return new Promise((resolve, reject) => {
try {
db = new Loki('db.lokidb', {
autoload: true,
autoloadCallback: function() {
resolve(db);
},
});
} catch (error) {
reject(error);
}
});
}
export function getCollection(collectionName) {
return db.getCollection(collectionName);
}
export function updateTalentsIcon(videoList) {
let talentsIconCollection = db.getCollection('talentsIcon');
// Iterate through videoList and add or update name and talent.iconImageUrl to the talentsIcon collection
videoList.forEach(video => {
let existingEntry = talentsIconCollection.findOne({ name: video.name });
if (existingEntry) {
// Update the existing entry
if (existingEntry.iconImageUrl !== video.talent.iconImageUrl) {
existingEntry.iconImageUrl = video.talent.iconImageUrl;
talentsIconCollection.update(existingEntry);
console.log("updated", video.name)
}
} else {
// Insert a new entry
talentsIconCollection.insert({
name: video.name,
iconImageUrl: video.talent.iconImageUrl
});
console.log("inserted", video.name)
}
});
}
export function saveDB(){
db.saveDatabase(err => {
if (err) {
throw err;
} else {
console.log('Database saved.');
}
});
}