36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
module.exports = ($app) => {
|
|
const ASSETS_DIR = "/pb_hooks/assets";
|
|
const getAsset = (name) => $filesystem.fileFromPath(ASSETS_DIR + "/" + name);
|
|
const getId = (id) => id.padStart(15, 0);
|
|
const id_v = getId("1"); //id_vocabulary
|
|
const id_c = getId("2"); //id_connectives
|
|
|
|
let row_array = [
|
|
[getId("1"), "keyboard", getAsset("keyboard.jpg"), getId("1")],
|
|
[getId("2"), "mouse", getAsset("mouse.jpg"), getId("1")],
|
|
];
|
|
dirtyTruncateTable("QuizLPQuestions");
|
|
|
|
let lt_collection = $app.findCollectionByNameOrId("QuizLPQuestions");
|
|
|
|
for (let i = 0; i < row_array.length; i++) {
|
|
let lesson_type = row_array[i];
|
|
|
|
let record = new Record(lt_collection);
|
|
record.set("id", lesson_type[0]);
|
|
record.set("word", lesson_type[1]);
|
|
record.set("sound", lesson_type[2]);
|
|
record.set("cat_id", lesson_type[3]);
|
|
|
|
$app.save(record);
|
|
}
|
|
|
|
console.log(`021 QuizLPQuestions done`);
|
|
};
|
|
|
|
const dirtyTruncateTable = (COLLECTION_NAME) => {
|
|
console.log(`perform dirty method to truncate table "${COLLECTION_NAME}"`);
|
|
const cmd_to_exec = $os.cmd("sqlite3", "/pb_data/data.db", `DELETE from ${COLLECTION_NAME};`);
|
|
cmd_to_exec.output();
|
|
};
|