sqlite.js 729 Bytes
Newer Older
XFT's avatar
XFT committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const Sequelize = require('sequelize');

const sequelize = new Sequelize({ dialect: 'sqlite', storage: 'notes.sqlite', logging: false });

global.sqlite = {
  initialize: async () => await sequelize.sync(),
  fetchNotes: async () => await sqlite.Note.findAll({ where: { spent: false } }),
  fetchShifterNotes: async (shifter) => await sqlite.Note.findAll({ where: { shifter: shifter } }),
  spentNote: async (note) => await sqlite.Note.update({ spent: true }, { where: { note: note } }),
  saveNote: async (note) => await sqlite.Note.create({ note: note.note, shifter: note.shifter, spent: false }),
  Note: sequelize.define('note', {
    shifter: Sequelize.STRING,
    note: Sequelize.STRING,
    spent: Sequelize.BOOLEAN
  })
}