-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_events.js
45 lines (39 loc) · 1.15 KB
/
load_events.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
//# Load all Ontario events into the db
//this is expected to run only once per season
const tba = require('./tba.js');
const db = require('./scouting.js');
async function load_events (connection, events) {
if (!events) {
console.log("No events in that district");
connection.end();
}
console.log(`Loading ${events.length} events`);
await Promise.all(events.map(event => add_event(connection, event.key)))
.then(() => connection.end())
.catch((err) => console.error("Something went wrong: " + err));
console.log("done");
}
//# Using connection to database, add event_code
async function add_event(connection, event_code) {
console.log(event_code);
return new Promise(
(resolve, reject) =>
connection.query("INSERT INTO frc_event (event_code) " +
"VALUES(?) " +
"ON DUPLICATE KEY UPDATE event_code = event_code",
[event_code],
((error, results, fields) => {
(error)
? reject(error)
: resolve()
}
)
)
);
}
if (require.main === module) {
db.with_connection(
connection =>
tba.all_events(events => load_events(connection, events)
));
}