-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete_words.js
51 lines (42 loc) · 2.21 KB
/
delete_words.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
48
49
50
51
var ask = require("./helpers/ask.js").ask,
color = require("./helpers/color.js").color,
db = require("./helpers/db.js").db,
lang = "en",
word_ids = [];
ask("Enter language: ", function (lang)
{
ask("Enter a comma separated list of IDs: ", function (ids)
{
try {
word_ids = JSON.parse("[" + ids + "]");
} catch (e) {}
if (word_ids.length) {
ask(color("Do you really want to delete " + word_ids.length + " word" + (word_ids.length === 1 ? "" : "s") + " from bible_" + lang + "?", ["red", "bold"]) + " (y/n) ", function(sure)
{
var table_name = "`bible_" + lang + "`";
sure = sure.toLowerCase();
if (sure === "y" || sure === "yes") {
word_ids.sort();
word_ids.forEach(function (id, i)
{
var paragraph;
/// Since it deletes one word each time, we must also move the ID back one each time.
id = Number(id) - i;
console.log("Deleting " + id);
/// Get paragraph info
paragraph = db.query_sync("SELECT paragraph FROM " + table_name + " WHERE id = " + id);
db.query_sync("DELETE FROM " + table_name + " WHERE id = " + id);
db.query_sync("UPDATE " + table_name + " SET lang_order = (lang_order - 1) WHERE id > " + id + " AND lang_order > 0");
db.query_sync("UPDATE " + table_name + " SET paragraph = " + Number(paragraph[0].paragraph) + " WHERE id = (" + id + " + 1)");
db.query_sync("UPDATE " + table_name + " SET id = (id - 1) WHERE id > " + id);
});
console.log("Deleted " + color(word_ids.length, "underline") + " words. Don't forget to edit the file.");
} else {
console.log("I didn't think so.");
}
});
} else {
console.log("Nothing to do.");
}
});
});