insomnia/app/models/stats.js

37 lines
672 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 name = 'Stats';
export const type = 'Stats';
export const prefix = 'sta';
export const canDuplicate = false;
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 migrate (doc) {
return doc;
}
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 create();
} else {
return results[0];
}
}