typicode / lowdb

Simple and fast JSON database
MIT License
21.35k stars 918 forks source link

lowdb2(esm) How to increase 1 ? #501

Closed hoonion90 closed 3 years ago

hoonion90 commented 3 years ago

how to increase db.json visitors + 1 ?

index.js

import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
import { LowSync, JSONFileSync } from "lowdb";
import _ from 'lodash'
const __dirname = dirname(fileURLToPath(import.meta.url));
const file = join(__dirname, 'db.json')
const adapter = new JSONFileSync(file)
const db = new LowSync(adapter)

db.read();
db.chain = _.chain(db.data);
//db.chain.update('visitors', n => n + 1);

db.json

{
  "visitors": 8000
}
typicode commented 3 years ago

db.chain.update('visitors', n => n + 1).value() value() is required to execute chain