insomnia/app/backend/models/stats.js
2016-11-08 20:26:49 -08:00

30 lines
571 B
JavaScript

import * as db from '../database';
export const type = 'Stats';
export const prefix = 'sta';
export function init () {
return db.initModel({
lastLaunch: Date.now(),
lastVersion: null,
launches: 0
});
}
export function create (patch = {}) {
return db.docCreate(type, patch);
}
export async function update (patch) {
const stats = await get();
return db.docUpdate(stats, patch);
}
export async function get () {
const results = await db.all(type);
if (results.length === 0) {
return await create();
} else {
return results[0];
}
}