-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulation_db.js
More file actions
38 lines (33 loc) · 848 Bytes
/
Copy pathsimulation_db.js
File metadata and controls
38 lines (33 loc) · 848 Bytes
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
//const Database = require('better-sqlite3');
import Database from 'better-sqlite3';
const db = new Database('simulation.db');
// Create tables if they don't exist
db.prepare(`
CREATE TABLE IF NOT EXISTS portfolio (
symbol TEXT PRIMARY KEY,
quantity INTEGER,
avgPrice REAL
)
`).run();
db.prepare(`
CREATE TABLE IF NOT EXISTS transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT,
symbol TEXT,
quantity INTEGER,
price REAL,
date TEXT
)
`).run();
db.prepare(`
CREATE TABLE IF NOT EXISTS cash (
id INTEGER PRIMARY KEY CHECK (id = 1),
balance REAL
)
`).run();
// Initialize with 100,000 TRY if not set
const cashExists = db.prepare("SELECT * FROM cash WHERE id = 1").get();
if (!cashExists) {
db.prepare("INSERT INTO cash (id, balance) VALUES (1, ?)").run(10000);
}
export { db };