You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
847 B

2 years ago
import Store from './_store.js'
/**
*
*
*
*/
class State extends Store {
/**
*
* @param {string} name
*
*/
add(data) {
const result = this.findOneByName(data.name)
if (!result) {
this._db.prepare('INSERT INTO states (name, date_lastrun) VALUES (:name, :date_lastrun)')
.run(data)
} else {
this._db.prepare('UPDATE states SET name = @name, date_lastrun = @date_lastrun WHERE id = ?')
.run(data, result.id)
}
return this.findOneByName(data.name)
}
/**
*
* @param {string} name
*
*/
findOneByName(name) {
const result = this._db.prepare('SELECT id, name, date_lastrun FROM states WHERE name = ?')
.get(name)
return result
}
}
export default State