upgrade to lowdb 6.1.1 and use JSONPreset

See example in https://github.com/typicode/lowdb/releases/tag/v6.1.0
This commit is contained in:
Ralf Vogler 2023-11-02 16:18:25 +01:00
parent 280ab70975
commit bf870919a6
3 changed files with 19 additions and 25 deletions

10
util.js
View file

@ -11,14 +11,8 @@ export const dataDir = s => path.resolve(__dirname, 'data', s);
export const resolve = (...a) => a.length && a[0] == '0' ? null : path.resolve(...a);
// json database
import { Low } from 'lowdb';
import { JSONFile } from 'lowdb/node';
export const jsonDb = async (file, defaultData) => {
const db = new Low(new JSONFile(dataDir(file)), defaultData);
await db.read();
return db;
};
import { JSONPreset } from 'lowdb/node';
export const jsonDb = (file, defaultData) => JSONPreset(dataDir(file), defaultData);
export const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
// date and time as UTC (no timezone offset) in nicely readable and sortable format, e.g., 2022-10-06 12:05:27.313