insomnia/app/backend/database/models/stats.js
Gregory Schier 318c35c2cb Move a bunch of stuff to async/await (#39)
* Some minor implementations

* Some more

* Lots more

* Removed 'backend' alias

* removed all promises

* Removed a bunch of module exports stuff

* Some morE'

* Fix

* custom DNS

* Tests for DNS

* bug fix

* Some small adjustments

* Small stuff
2016-10-02 13:57:00 -07:00

32 lines
583 B
JavaScript

'use strict';
const db = require('../index');
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];
}
}