insomnia/app/backend/database/models/stats.js

32 lines
583 B
JavaScript
Raw Normal View History

2016-09-21 20:32:45 +00:00
'use strict';
2016-09-22 01:26:40 +00:00
const db = require('../index');
2016-09-21 20:32:45 +00:00
export const type = 'Stats';
export const prefix = 'sta';
export function init () {
return db.initModel({
lastLaunch: Date.now(),
lastVersion: null,
launches: 0
});
}
2016-09-21 20:32:45 +00:00
export function create (patch = {}) {
return db.docCreate(type, patch);
}
2016-09-21 20:32:45 +00:00
export async function update (patch) {
const stats = await get();
return db.docUpdate(stats, patch);
}
2016-09-21 20:32:45 +00:00
export async function get () {
const results = await db.all(type);
if (results.length === 0) {
return await create();
} else {
return results[0];
}
}