2017-11-23 01:26:10 +00:00
|
|
|
'use strict'
|
|
|
|
|
2018-01-06 15:54:00 +00:00
|
|
|
const fs = require('fs')
|
2017-11-23 14:19:43 +00:00
|
|
|
const os = require('os')
|
2018-01-05 22:31:00 +00:00
|
|
|
const path = require('path')
|
2017-11-23 14:19:43 +00:00
|
|
|
const sqlite3 = require('sqlite3').verbose()
|
|
|
|
const squel = require('squel')
|
2018-01-05 22:31:00 +00:00
|
|
|
|
2018-01-06 15:55:52 +00:00
|
|
|
const DB_FILE = path.join(os.homedir(), '.intval3.db')
|
2017-11-23 14:19:43 +00:00
|
|
|
const db = new sqlite3.Database(DB_FILE)
|
|
|
|
|
|
|
|
class DB {
|
|
|
|
constructor () {
|
|
|
|
this._table = 'frames'
|
|
|
|
this.createTable()
|
|
|
|
}
|
|
|
|
createTable () {
|
|
|
|
const query = `CREATE TABLE
|
|
|
|
IF NOT EXISTS ${this._table} (
|
2017-11-23 14:29:44 +00:00
|
|
|
dir INTEGER,
|
2017-11-23 14:19:43 +00:00
|
|
|
exposure INTEGER,
|
|
|
|
start INTEGER,
|
|
|
|
stop INTEGER,
|
|
|
|
len INTEGER,
|
2017-11-23 14:46:18 +00:00
|
|
|
counter INTEGER,
|
|
|
|
sequence INTEGER
|
2017-11-23 14:19:43 +00:00
|
|
|
);`
|
|
|
|
db.run(query)
|
|
|
|
}
|
|
|
|
insert (obj) {
|
|
|
|
const query = squel.insert()
|
|
|
|
.into(this._table)
|
|
|
|
.setFields(obj) //dir, exposure, start, stop, len, counter
|
|
|
|
.toString()
|
|
|
|
db.run(query)
|
|
|
|
}
|
2017-11-23 14:34:24 +00:00
|
|
|
find (where, cb) {
|
2017-11-23 14:35:47 +00:00
|
|
|
const query = squel.select()
|
2017-11-23 14:34:24 +00:00
|
|
|
.from(this._table)
|
|
|
|
.where(where)
|
|
|
|
.toString()
|
|
|
|
db.all(query, cb)
|
|
|
|
}
|
|
|
|
list (cb) {
|
2017-11-23 14:35:47 +00:00
|
|
|
const query = squel.select()
|
2017-11-23 14:34:24 +00:00
|
|
|
.from(this._table)
|
|
|
|
.toString()
|
|
|
|
db.all(query, cb)
|
|
|
|
}
|
2017-11-23 14:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new DB()
|