GithubHelp home page GithubHelp logo

typicode / lowdb Goto Github PK

View Code? Open in Web Editor NEW
20.9K 243.0 896.0 1.37 MB

Simple and fast JSON database

License: MIT License

Shell 0.88% JavaScript 99.12%
database lodash nodejs localstorage electron json embedded-database embeddable javascript storage

lowdb's Introduction

lowdb Node.js CI

Simple to use type-safe local JSON database ๐Ÿฆ‰

If you know JavaScript, you know how to use lowdb.

Read or create db.json

const db = await JSONFilePreset('db.json', { posts: [] })

Use plain JavaScript to change data

const post = { id: 1, title: 'lowdb is awesome', views: 100 }

// In two steps
db.data.posts.push(post)
await db.write()

// Or in one
await db.update(({ posts }) => posts.push(post))
// db.json
{
  "posts": [
    { "id": 1, "title": "lowdb is awesome", "views": 100 }
  ]
}

In the same spirit, query using native Array functions:

const { posts } = db.data

posts.at(0) // First post
posts.filter((post) => post.title.includes('lowdb')) // Filter by title
posts.find((post) => post.id === 1) // Find by id
posts.toSorted((a, b) => a.views - b.views) // Sort by views

It's that simple. db.data is just a JavaScript object, no magic.

Sponsors





Become a sponsor and have your company logo here ๐Ÿ‘‰ GitHub Sponsors

Features

  • Lightweight
  • Minimalist
  • TypeScript
  • Plain JavaScript
  • Safe atomic writes
  • Hackable:
    • Change storage, file format (JSON, YAML, ...) or add encryption via adapters
    • Extend it with lodash, ramda, ... for super powers!
  • Automatically switches to fast in-memory mode during tests

Install

npm install lowdb

Usage

Lowdb is a pure ESM package. If you're having trouble using it in your project, please read this.

import { JSONFilePreset } from 'lowdb/node'

// Read or create db.json
const defaultData = { posts: [] }
const db = await JSONFilePreset('db.json', defaultData)

// Update db.json
await db.update(({ posts }) => posts.push('hello world'))

// Alternatively you can call db.write() explicitely later
// to write to db.json
db.data.posts.push('hello world')
await db.write()
// db.json
{
  "posts": [ "hello world" ]
}

TypeScript

You can use TypeScript to check your data types.

type Data = {
  messages: string[]
}

const defaultData: Data = { messages: [] }
const db = await JSONPreset<Data>('db.json', defaultData)

db.data.messages.push('foo') // โœ… Success
db.data.messages.push(1) // โŒ TypeScript error

Lodash

You can extend lowdb with Lodash (or other libraries). To be able to extend it, we're not using JSONPreset here. Instead, we're using lower components.

import { Low } from 'lowdb'
import { JSONFile } from 'lowdb/node'
import lodash from 'lodash'

type Post = {
  id: number
  title: string
}

type Data = {
  posts: Post[]
}

// Extend Low class with a new `chain` field
class LowWithLodash<T> extends Low<T> {
  chain: lodash.ExpChain<this['data']> = lodash.chain(this).get('data')
}

const defaultData: Data = {
  posts: [],
}
const adapter = new JSONFile<Data>('db.json', defaultData)

const db = new LowWithLodash(adapter)
await db.read()

// Instead of db.data use db.chain to access lodash API
const post = db.chain.get('posts').find({ id: 1 }).value() // Important: value() must be called to execute chain

CLI, Server, Browser and in tests usage

See src/examples/ directory.

API

Presets

Lowdb provides four presets for common cases.

  • JSONFilePreset(filename, defaultData)
  • JSONFileSyncPreset(filename, defaultData)
  • LocalStoragePreset(name, defaultData)
  • SessionStoragePreset(name, defaultData)

See src/examples/ directory for usage.

Lowdb is extremely flexible, if you need to extend it or modify its behavior, use the classes and adapters below instead of the presets.

Classes

Lowdb has two classes (for asynchronous and synchronous adapters).

new Low(adapter, defaultData)

import { Low } from 'lowdb'
import { JSONFile } from 'lowdb/node'

const db = new Low(new JSONFile('file.json'), {})
await db.read()
await db.write()

new LowSync(adapterSync, defaultData)

import { LowSync } from 'lowdb'
import { JSONFileSync } from 'lowdb/node'

const db = new LowSync(new JSONFileSync('file.json'), {})
db.read()
db.write()

Methods

db.read()

Calls adapter.read() and sets db.data.

Note: JSONFile and JSONFileSync adapters will set db.data to null if file doesn't exist.

db.data // === null
db.read()
db.data // !== null

db.write()

Calls adapter.write(db.data).

db.data = { posts: [] }
db.write() // file.json will be { posts: [] }
db.data = {}
db.write() // file.json will be {}

db.update(fn)

Calls fn() then db.write().

db.update((data) => {
  // make changes to data
  // ...
})
// files.json will be updated

Properties

db.data

Holds your db content. If you're using the adapters coming with lowdb, it can be any type supported by JSON.stringify.

For example:

db.data = 'string'
db.data = [1, 2, 3]
db.data = { key: 'value' }

Adapters

Lowdb adapters

JSONFile JSONFileSync

Adapters for reading and writing JSON files.

import { JSONFile, JSONFileSync } from 'lowdb/node'

new Low(new JSONFile(filename), {})
new LowSync(new JSONFileSync(filename), {})

Memory MemorySync

In-memory adapters. Useful for speeding up unit tests. See src/examples/ directory.

import { Memory, MemorySync } from 'lowdb'

new Low(new Memory(), {})
new LowSync(new MemorySync(), {})

LocalStorage SessionStorage

Synchronous adapter for window.localStorage and window.sessionStorage.

import { LocalStorage, SessionStorage } from 'lowdb/browser'
new LowSync(new LocalStorage(name), {})
new LowSync(new SessionStorage(name), {})

Utility adapters

TextFile TextFileSync

Adapters for reading and writing text. Useful for creating custom adapters.

DataFile DataFileSync

Adapters for easily supporting other data formats or adding behaviors (encrypt, compress...).

import { DataFile } from 'lowdb'
new DataFile(filename, {
  parse: YAML.parse,
  stringify: YAML.stringify
})
new DataFile(filename, {
  parse: (data) => { decypt(JSON.parse(data)) },
  stringify: (str) => { encrypt(JSON.stringify(str)) }
})

Third-party adapters

If you've published an adapter for lowdb, feel free to create a PR to add it here.

Writing your own adapter

You may want to create an adapter to write db.data to YAML, XML, encrypt data, a remote storage, ...

An adapter is a simple class that just needs to expose two methods:

class AsyncAdapter {
  read() {
    /* ... */
  } // should return Promise<data>
  write(data) {
    /* ... */
  } // should return Promise<void>
}

class SyncAdapter {
  read() {
    /* ... */
  } // should return data
  write(data) {
    /* ... */
  } // should return nothing
}

For example, let's say you have some async storage and want to create an adapter for it:

import { api } from './AsyncStorage'

class CustomAsyncAdapter {
  // Optional: your adapter can take arguments
  constructor(args) {
    // ...
  }

  async read() {
    const data = await api.read()
    return data
  }

  async write(data) {
    await api.write(data)
  }
}

const adapter = new CustomAsyncAdapter()
const db = new Low(adapter)

See src/adapters/ for more examples.

Custom serialization

To create an adapter for another format than JSON, you can use TextFile or TextFileSync.

For example:

import { Adapter, Low } from 'lowdb'
import { TextFile } from 'lowdb/node'
import YAML from 'yaml'

class YAMLFile {
  constructor(filename) {
    this.adapter = new TextFile(filename)
  }

  async read() {
    const data = await this.adapter.read()
    if (data === null) {
      return null
    } else {
      return YAML.parse(data)
    }
  }

  write(obj) {
    return this.adapter.write(YAML.stringify(obj))
  }
}

const adapter = new YAMLFile('file.yaml')
const db = new Low(adapter)

Limits

Lowdb doesn't support Node's cluster module.

If you have large JavaScript objects (~10-100MB) you may hit some performance issues. This is because whenever you call db.write, the whole db.data is serialized using JSON.stringify and written to storage.

Depending on your use case, this can be fine or not. It can be mitigated by doing batch operations and calling db.write only when you need it.

If you plan to scale, it's highly recommended to use databases like PostgreSQL or MongoDB instead.

lowdb's People

Contributors

alvaropinot avatar arondight avatar cedmax avatar chamini2 avatar crashmax-dev avatar creaturephil avatar dependabot[bot] avatar drownbes avatar etiktin avatar greenkeeper[bot] avatar jackall3n avatar julienitard avatar kpotschi avatar levrik avatar lijunle avatar mukhlisakbr avatar naveloranges avatar nightwolfz avatar npmcdn-to-unpkg-bot avatar ozanmuyes avatar pawel-schmidt avatar root-core avatar sehnpaa avatar shockey avatar slathrop avatar spectral-software avatar surajjha avatar typicode avatar vhpoet avatar wykhuh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lowdb's Issues

A refresh API?

i find another application changed the db, but anything has changed in this application, because all data is in the memory. I think refresh API is nessary.

How to deal with errors?

So far, I'm wrapping every single database interaction within a try/catch block, like:

try {
    return users.find({ name: 'john' }).email;
} catch (e) {
    return console.log("Error while trying to get the user's email.");
}

Is that the way to go?

Handling multiple nodes using the same db

I've been getting an error originating from the following snippet when running multiple nodes on production:
./src/disk.js

fs.rename(getTempFile(file), file, function(err) {
if (err) throw err
next()
})

The issue is that the tempFile used in both nodes is the same, and all of the nodes are creating and trying to remove it altogether.
A suggested fix for this problem would be to use randomly generated tempFile and I would love to create a pull request fixing this issue if needed.
btw, good job on that lib, I love it!

Calling db() with non-existent collection shouldn't auto-create it

Right now, every call to db('someCollectionName') will create given collection if it doesn't exists. That's not always wanted, like when you just want to check for its existence instead.

Changing this behaviour shouldn't be a problem, since the collection could be auto-created on the first insert call.

Find by nested objects

How to find by nested objects?

books : {
author : { id : 1 }
title: 'Book Title'
}

I want to find by author id..

Return data by value rather by reference?

Hi there,

First of all, nice project - great for mocking things up!

I am getting what I would consider unexpected behaviour, even though I am pretty sure I know why this happening. Consider that I might have a user collection, and I want to display data differently depending on whether the person looking at a user object is the actual user or someone else.

In MongoDB for example, I would pull back the entire user object and then filter attributes according to the user who made the request. One method of filtering is to simply delete keys from the returned object before passing it back as a response.

But if I do that using LowDB, here is what happens (in the node REPL):

> var low = require('lowdb');
undefined
> var db = low();
undefined
> var user = {id: '1', keeper: 'will stay', throwaway: 'will be deleted'}
undefined
> db('users').push(user)
{ __chain__: true,
  __wrapped__: 
   [ { id: '1',
       keeper: 'will stay',
       throwaway: 'will be deleted' } ] }
> console.dir(db.object)
{ users: [ { id: '1', keeper: 'will stay', throwaway: 'will be deleted' } ] }
undefined
> var data = db('users').find({id: '1'}).value()
undefined
> data
{ id: '1',
  keeper: 'will stay',
  throwaway: 'will be deleted' }
> var x = true
true
> if (x) {console.log(data)} else {delete data.throwaway; console.log(data)}
{ id: '1', keeper: 'will stay', throwaway: 'will be deleted' }
undefined
> x = false
false
> if (x) {console.log(data)} else {delete data.throwaway; console.log(data)}
{ id: '1', keeper: 'will stay' }
undefined
> console.dir(db.object)
{ users: [ { id: '1', keeper: 'will stay' } ] }
undefined

I'm assuming that is happening because the query result is coming back as a reference rather than as a value, which is unexpected - if this was an actual database, there is no way variable manipulation outside of the database would end up in writes to the database.

I know this is not designed to be a 'real' database, but I don't think it should behave in this way... or am I using lodash incorrectly?

user json-server with lowdb

you say : " if you make POST, PUT, PATCH or DELETE requests, changes will be automatically and safely saved to db.json using lowdb.",how to use json-server with lowdb ,can you write a demo ? thank you ,

data loss if process hangs/crashes on same event tick

this may be related to #23

in short, we've seen various data loss conditions occur which seem to be related to the async nature of the writes. the easiest way to simulate this is:

var low = require('lowdb');
var db = low('db.json');
var collection = db('kaiju');
collection.push({name: 'godzilla'});

...wait a moment...

collection.push({name: 'mothra'}); process.exit();

the content of db.json would then be:

{
  "kaiju": [
    {
      "name": "godzilla"
    }
  ]
}

I like this project because it's a quick hack for a lot of use cases so I am curious what the recommended approach is when a crash/hang is detected. Is there a synchronous save() call which can be attempted if needed?

Suggesting an `autosave` option

// Compose every function with fn
function composeAll(obj, fn) {
  for (var key in obj) {
    if (_.isFunction(obj[key])) {
      obj[key] = _.compose(fn, obj[key])
    }
  }
}

Hey, I doubt the composing on all functions including irrelevant ones (like isRegExp)
Shall we pick out the ones?
Or give it an autosave option which defaults to true, like:

var db = low(filename, { autosave: false })

Concatenation doesn't seemt to update the db.

Im not sure if im doing this wrong. I am just trying to concatenate 2 arrays with the below code

//This doesn't work
db('test').concat([3,4]);
db.save();

//This works
db('test').chain().assign(db.object.test.concat([3,4])).value();

Is this a bug? Is there a easier syntax then the second one?

Put value to db key to override existed value.

Can we do something like this:
db('test').put({test:'test'}); and override data in 'test' with object {test:'test'}

I understand that you can do db.object.test = {test:'test'} but then you need to do db.save()

Asynch write

I'm trying to run a JavaScript code in Node.JS and no write is made until the termination of the program. I'm using standard parameters so async = true.

Sorting pre-existing DB

I've been trying to follow your examples of how to sort a database but to no success. Here's what's happening...

I have a collection called photos with a field called index which spans 1-100. After the DB with this collection has been created I'm trying to sort it with something like this:

var low = require('lowdb');
var lowDB = 'data/photos.json';
low.path = lowDB;
low.load(lowDB);

low('photos').sortBy('index').save(lowDB);

This almost works except it extracts the data from the collection's array.

That is, it goes from:

{
  "photos": [
    {
        "index": ....

to:

[
  {
    "index": ...

If I remove the .save(lowDB), nothing happens to JSON and it remains unsorted.

Am I doing something wrong here?

Any help is much appreciated.

[Question] Performance

Hello.

Thank you for opensourcing this great library. I love the simple API.

I want to know if lowdb is fast enough to be used in a webapp that has ~50-100 concurrent users.

Potential data loss due to throttled save() calls

Thank you for developing LowDB! It is an awesome library and a great fit for small scripts and apps.

However there is one issue that I am facing. Because the save() call is throttled using lodash's _.throttle, if there are a batch of lowdb operations only the first one is persisted to disk. In a lot of situations subsequent batches of save() calls might arrive minutes or hours apart, which is a large window with no persistence.

So here is my suggestion. Would it be possible to use lodash's _.debounce instead? It looks perfect for the job and a save to disk is guaranteed to follow after every batch of lowdb operations.

Access external file

I want to build a app(.exe extension) that use external json files. After make app to exe i cant access external files. Actually i dont know how to.

var low = require('lowdb');
var settings = low("data/settings.json");

i want to access this file after make executable. it only use json in exe. if i dont include it, app try to find it in exe(nw or zip).

Is there a solution for my problem?

Thank you and sorry for bad english.

insertOrUpdate method?

any easy way to :

  1. giving namespace: 'sth' and one rule item
  2. if interface not exist, insert
  3. otherwise update it's rules
  4. if rules name exist, update, otherwise insert.
{
  interface: [
    {
       namespace: 'a',
       rules: [
         {name: 'rule1', content: 'xxx'}
       ]
    }
  ]
}

how to remove exist key when update

db data: {id:1, key1: 'value1' , key2: 'value2'}
web post: {id:1, key1: 'value1' }
want to update db to replace.

offer an method replaceWhere ?

Short syntax update method do not work

By Readme document, update example
low('songs', id, {title: 'new title'}) (1)
// == low('songs').update(id, {title: 'new title'}).value() (2)

(2)work fine, but (1) does not work.
Please help me, thanks.

Override `stringify` and `parse` on each `db`

How about this way:

db = low(syncFile, {
  stringify: function() { return '{ "foo": [] }' },
  parse: function() { return { bar: [] } }
})

So we could override each db separately
I'm ready to provide a PR if accepted ;-)

remove not working

var low = require('lowdb');
low.mixin(require('underscore-db'));
var db = low('db.json');
db('file').insert({name: '1.jpg',dir: 'test',size: 1024});
console.log(db('file').value())
/*
[ { name: '1.jpg',
    dir: 'test',
    size: 1024,
    id: '97f5caa4-2fb2-48bf-bfe5-42b26735387d' } ]
*/
db('file').remove({name: '1.jpg',dir: 'test'});
console.log(db('file').value());
/*
[ { name: '1.jpg',
    dir: 'test',
    size: 1024,
    id: '97f5caa4-2fb2-48bf-bfe5-42b26735387d' } ]
*/

Is lowdb gonna support encryption?

// for example
var db = low(dbfile, {
  password: 'xxxxxxxx'
})
// and the dbfile gets encrypted/decrypted while w/r
// to enable user-auth

Order by field inside a object

Hello guys, first of all congratz for your work, this database are helping me a lot ๐Ÿ’ƒ
I need a help here, need create a order by a field inside a object like this
.chain()
.where(criteria)
.sortBy(
{
term: {
weight
}
}
)
.value();

but this return an error "weight is not defined" i dont understand, this appears don't working properly, can you guys help me?

error when executing low.mixin

var low = require('lowdb');
var _contrib = require('underscore-contrib') // For getPath()
var _db = require('underscore.db')

low.mixin(_contrib);
low.mixin(_db);

I saw your example to insert json with inner nodes of the other json. but I get this error when I execute the same code.
Not sure what is missing here.

image

Thanks,

Events functionality

Im using this module with json-server, it's amazing :) I've got just question whether there is an easy way to achieve events functionality when some data is set to db?

Update doesn't works

I'm trying to update a record executing this code:

db('user').chain().where({ 'userid': 1 }).first().assign({ 'name': 'john' }).value();

but it does not save the new field on my db
user is still:
{ "user": [ { "userid": "1" } ] }

error install on windows

Hi everybody,

i tried install lowdb 0.4.2 and catch a error with node_module graceful.

check my command :

npm update --save lowdb

npm http 304 https://registry.npmjs.org/lodash
npm ERR! Error: No compatible version found: graceful-fs@'^3.0.2'
npm ERR! Valid install targets:
npm ERR! ["1.0.0","1.0.1","1.0.2","1.1.0","1.1.1","1.1.2","1.1.3","1.1.4","1.1.5","1.1.6","1.1.7","1.1.8","1.1.9","1.1.1
0","1.1.11","1.1.12","1.1.13","1.1.14","1.2.0","1.2.1","1.2.2","1.2.3","2.0.0","2.0.1","2.0.2","2.0.3","3.0.0","3.0.1","
3.0.2","3.0.3"]

Multiple databases

Instead of:

low('songs').insert({title: 'low!'});

Where the database is defaulted to a global db.json, I'd rather:

var db = low('db.json');
db('songs').insert({title: 'low!'});

So I can separate stuff into multiple databases where need be.

why can't i just do that ? :-)

var _folder = 
    {
        "type": "folder",
        "name": "paris",
        "createdAt": Date.now(),
        "updatedAt": Date.now(),
        "items": []     
    };

var low = require('lowdb');

var folder = low('travel').insert(_folder).value();

var _folderinside =
    {
        "type": "folder",
        "name": "videos",
        "createdAt": Date.now(),
        "updatedAt": Date.now(),
        "items": []     
    };

var song  = low('travel').get(folder.id)('items').insert(_folderinside).value();

console.log(song);

i think its a nice idea.

Sorting existing database error

Have some problem with sorting object by key = "created_time" in the array, have been trying a lot of methods but nothing working for me

This issue ticket didn't help me link

What I have

var low = require('lowdb');
var db = low("./database/db.json");

db('dbname').push({object});
db('dbname').push({object});
db('dbname').push({object});
and more

After filled database I have this

{
 "dbname": [
  {
     "created_time": "..."
  },
  {
    ...
  },
 ...
} 

This is how I tried to sort object in array by "created_time" value

db.object.dbname = db('dbname').sortBy('created_time').value();
db.save();

or thus

db('dbname ').chain().sortBy('created_time').value();
db.save();

In both cases I get this error

..., [object Object],[object Object] has no method 'value'

Add a simple object, no array

How can I add a simple object to the db? Not pushed into an array. See the desired result below:

{
    "info": {
       "title": "some title",
       "description": "some description"
   }
}

I haven't had any luck with insert or update:

db('info').insert({ title: 'some title', description: 'some description' }); 
// error: db(...).insert is not a function

Also, I wonder what happened to the earlier 'Short Syntax' still available online here?

reload underlying data

Much appreciate your work on this.
Is there a way to force a reload from disk?

For now, I've just added a reload function to the db object which just reruns the initial data read and parse routine.
This is convenient for me during the development process.

Documentation find all

I'm sorry if it's obvious. But how do I get an instance of all documents in the database? I tried .find()

Use graceful-fs

@typicode, have you considered using graceful-fs instead of the normal fs module?
It's a drop-in replacement for the fs module that adds a couple of improvements for handling some edge cases. For example in the past I add problems using rename on Windows because of antivirus locking the folder, using graceful-fs solved it for me (it retries the rename for a certain duration).
What do you think?

problems reading from db.js

node version: v0.11.13
When I insert something I can immediately read it back. However when I restart my app I get nothing back even though my data exists inside of db.js.

Chained collection and underlying db.object become unsynced.

I'm not sure if this is intended. What is happening though is that the db.object doesn't match the chained version of the same object over time as altering methods are applied to the chain because each new chain produces only a copy of the wrapper, and though this wrapper can be 'realized' into the right form, that value never gets assigned to db.object.

Here is a 'failing' test showing what I mean:

    describe('Autosave syncing with db.object', function() {

      it("both db.object and db('coll').value() should be equal after alteration to underlying data", function() {
        var db = low(file3, { async: false });
        var c1 = db('stay-synced');
        c1.push({id: 1});
        c1.push({id: 2});

        assert(c1.size().value() === 2);

        c2 = c1.remove({})

        assert(c2.size().value() === 0);

        assert.equal(c2.size().value(), db.object['stay-synced'].length);
      })
    });


I think that a better approach might be to add default mixins that includes a 'save'. This would get around another problem: Every single method is composed with the save so even a find, or a pluck or a where, etc call the 'save()' method. Additionally, it might not be a good idea to expose db.object, at least not directly because syncing back to the chain seems like it might be pretty complex. I've got a local version that syncs db.object with the chain value after every chained method, but that doesn't seem appropriate either (because of find, pluck, filter, etc.)

Does the database stay in memory?

If I read the database in file1.js:

var users = require('lowdb')('./db.json')('users');

// do something with users

Does the package perform a second file read operation when I use it in file2.js:

var settings = require('lowdb')('./db.json')('settings');

// do something with settings

Or does it get read once after node index.js and it stays in memory?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.