insomnia/app/models/stats.js

30 lines
564 B
JavaScript
Raw Normal View History

2016-11-10 05:56:23 +00:00
import * as db from '../common/database';
2016-09-21 20:32:45 +00:00
export const type = 'Stats';
export const prefix = 'sta';
export function init () {
2016-11-10 01:15:27 +00:00
return {
lastLaunch: Date.now(),
lastVersion: null,
launches: 0
2016-11-10 01:15:27 +00:00
};
}
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];
}
}