In my project, i am using realm as a database to save some data. The data schema figured out below;
let aschema = new Realm({
schema: [{
name: 'Announcement',
properties: {
id: 'string',
title: 'string',
date: 'date',
content: 'string',
}
}],
schemaVersion: 5
});
I am fetching the data from an address and saving them to the announcement table via loadAnnouncements function;
export async function loadAnnouncements() {
url = 'http://192.168.1.xx/test.html'
const response = await fetch(url);
const htmlString = await response.text();
const $ = cio.load(htmlString);
const announcements = $("#tab tr")
.map((_, tr) => ({
id: $("h5 a",tr).attr("href"),
title: $("h5 a",tr).text(),
...
}));
for(let i = 0; i < announcements.length; i++){
announcement = new AnnouncementModel(announcements[i].id, announcements[i].title, ...);
AnnouncementService.save(announcement);
}
return announcements;
}
For each new announcement, a notification should be pushed. Therefore, old announcements should be populated for once after the installation like creation of a realm DB.
I think the problem is clear, how can i execute a function for once after the installation or at the same time?