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