const config = require("/pb_hooks/seed/config.js"); const utils = require("/pb_hooks/seed/utils.js"); module.exports = ($app) => { const { getId, getAsset, dirtyTruncateTable } = utils; const { id_v, id_c, cat_id_news, cat_id_sport, cat_id_tech, cat_id_art, cat_id_basic, cat_id_nature, cat_id_workplace, cat_id_connectives_1 } = config; // const getId = (id) => id.padStart(15, 0); let row_datas = [ [getId("1"), getAsset("keyboard.jpg"), getAsset("keyboard.mp3"), "keyboard", "鍵盤", "sample_e", "sample_c", cat_id_tech, "", id_v, "visible"], [getId("2"), getAsset("mouse.jpg"), getAsset("mouse.mp3"), "mouse", "滑鼠", "sample_e mouse", "sample_c mouse", cat_id_tech, "", id_v, "visible"], [getId("3"), getAsset("run.jpg"), getAsset("mouse.mp3"), "run", "跑步", "sample_e run", "sample_c run", cat_id_sport, "", id_v, "visible"], [getId("4"), getAsset("swim.jpg"), getAsset("mouse.mp3"), "swim", "游泳", "sample_e swim", "sample_c swim", cat_id_sport, "", id_v, "visible"], // [getId("5"), getAsset("news1.jpg"), getAsset("news1.mp3"), "news", "新聞", "sample_e news1", "sample_c news1", cat_id_news, "", id_v, "visible"], [getId("6"), getAsset("news2.jpg"), getAsset("news2.mp3"), "news", "新聞", "sample_e news2", "sample_c news2", cat_id_news, "", id_v, "visible"], [getId("7"), getAsset("art1.jpg"), getAsset("art1.mp3"), "art", "藝術", "sample_e art1", "sample_c art1", cat_id_art, "", id_v, "visible"], [getId("8"), getAsset("art2.jpg"), getAsset("art2.mp3"), "art", "藝術", "sample_e art2", "sample_c art2", cat_id_art, "", id_v, "visible"], [getId("9"), getAsset("basic1.jpg"), getAsset("basic1.mp3"), "basic", "基礎", "sample_e basic1", "sample_c basic1", cat_id_basic, "", id_v, "visible"], [getId("10"), getAsset("basic2.jpg"), getAsset("basic2.mp3"), "basic", "基礎", "sample_e basic2", "sample_c basic2", cat_id_basic, "", id_v, "visible"], [getId("11"), getAsset("nature1.jpg"), getAsset("nature1.mp3"), "nature", "自然", "sample_e nature1", "sample_c nature1", cat_id_nature, "", id_v, "visible"], [getId("12"), getAsset("nature2.jpg"), getAsset("nature2.mp3"), "nature", "自然", "sample_e nature2", "sample_c nature2", cat_id_nature, "", id_v, "visible"], [getId("13"), getAsset("workplace1.jpg"), getAsset("workplace1.mp3"), "workplace", "工作場所", "sample_e workplace1", "sample_c workplace1", cat_id_workplace, "", id_v, "visible"], [getId("14"), getAsset("workplace2.jpg"), getAsset("workplace2.mp3"), "workplace", "工作場所", "sample_e workplace2", "sample_c workplace2", cat_id_workplace, "", id_v, "visible"], // [getId("21"), getAsset("mouse.jpg"), getAsset("mouse.mp3"), "connectives 1", "連接詞 1", "connective sample_e 1", "connective sample_c 1", cat_id_connectives_1, "", id_c, "visible"], ]; dirtyTruncateTable("Vocabularies"); for (let i = 0; i < row_datas.length; i++) { let vocabularies_collection = $app.findCollectionByNameOrId("Vocabularies"); let data = row_datas[i]; let record = new Record(vocabularies_collection); record.set("id", data[0]); record.set("image", data[1]); record.set("sound", data[2]); record.set("word", data[3]); record.set("word_c", data[4]); record.set("sample_e", data[5]); record.set("sample_c", data[6]); record.set("cat_id", data[7]); record.set("category", data[8]); record.set("lesson_type_id", data[9]); record.set("visible", data[10]); $app.save(record); } console.log("done ?"); }; // TODO: delete me ? // 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(); // };