Last active
September 3, 2019 05:27
-
-
Save erichiller/fe0ca29c946cd46c7bccdab56ceaff0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs = require('fs'); | |
import sql = require('sql.js'); | |
export class Security { | |
private db; | |
private history: dayRecord[]; | |
constructor( | |
private symbol: string, | |
private dbname: string = "f.db" | |
) { | |
console.log("Security constructor for " + symbol); | |
this.db = new sql.Database(fs.readFileSync(path.join(__dirname, this.dbname))); | |
// date stored as ISO 8601 | |
this.writeSql("CREATE TABLE IF NOT EXISTS " + this.symbol + " ("+ | |
" `date` TEXT NOT NULL UNIQUE, " + | |
" `open` REAL NOT NULL, " + | |
" `high` REAL NOT NULL, " + | |
" `low` REAL NOT NULL, " + | |
" `close` REAL NOT NULL, " + | |
" `volume` NUMERIC, " + | |
" `adj_close` REAL, " + | |
" PRIMARY KEY(date) " + | |
"); "); | |
console.log("table created"); | |
} | |
writeSql(sqlstr: string) { | |
console.log("writeSql:"+sqlstr) | |
this.db.run(sqlstr); | |
fs.writeFileSync(this.dbname, new Buffer(this.db.export())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment