· 7 years ago · Feb 18, 2019, 06:06 PM
1"id": "EExKKTC8IuL",
2 "date": "2019-02-18T14:57:52.997Z",
3 "timestamp": "1550500384",
4 "title": "Financial Giant SBI Aims to Boost Ripple and Push XRP Ahead of Bitcoin in Crypto Market CapFinancial Giant SBI Aims to Boost Ripple and Push XRP Ahead of Bitcoin in Crypto Market Cap",
5 "score": 6,
6 "comparative": 0.18181818181818182
7
8try {
9
10 const table = "coinna"
11 const dbFile = "scraped"
12 const dataDir = "./data/"
13 const dbExt = ".db"
14
15 const dbConn = db(`${dataDir}${dbFile}${dbExt}`);
16 dbConn.prepare("PRAGMA journal_mode = WAL").run();
17 dbConn
18 .prepare(
19 `CREATE TABLE IF NOT EXISTS [${table}] (id PRIMARY KEY, date DATETIME, timestamp INT, title VARCHAR, score DECIMAL, comparative INT)`
20 )
21 .run();
22
23 const insertStmt = dbConn.prepare(
24 `INSERT INTO [${table}] (date, timestamp, title, score, comparative) VALUES (?, ?, ?, ?, ?)`
25 );
26 dbConn.transaction(() => {
27 parsedResults.forEach(
28 ({ date, timestamp, title, score, comparative }) =>
29 insertStmt.run(
30 date,
31 timestamp,
32 title,
33 score,
34 comparative
35 )
36 );
37 })
38 console.log(`${parsedResults.length} added to ${table}`);
39}
40
41 catch (e) {
42 console.log(e.message);
43 }