insomnia/app/backend/models/stats.js

30 lines
557 B
JavaScript
Raw Normal View History

2016-11-09 04:26:49 +00:00
import * as db from '../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];
}
}