A database library stores JSON file for Node.js.

Overview

concisedb

npm version codecov GitHub Stars NPM Downloads License Package size

English | 简体中文

A database library stores JSON file for Node.js.

Here is what updated every version if you want to know.

API Document

Usage

Basic usage

  1. Install this library

You can also use other package managers like yarn and pnpm instead

npm install concisedb
  1. Example code

This library also supports TypeScript

const ConciseDb = require('concisedb')
const path = require('path')

// The third argument is Options for the class. 
// Access https://v0.concisedb.top/ if you wanna know what options can change
const db = new ConciseDb(path.join(__dirname, 'db.json'), { test: [] })

db.data.test.push(1) // It will update JSON file automatically by using Proxy
// So for performance, if you need to change the data many times at once
// you can use db.getData() to get a copy of data
// Of course, you can give the class { realtimeUpdate: false } to the third argument
// to prevent the program from updating the JSON file automatically

console.log(db.data) // Output: { test: [ 1 ] }
import ConciseDb from 'concisedb'
import { join } from 'path'

interface Database {
  test: number[]
}

// The third argument is Options for the class. 
// Access https://v0.concisedb.top/ if you wanna know what options can change
const db = new ConciseDb<Database>(join(__dirname, 'db.json'), { test: [] })

db.data.test.push(1) // It will update JSON file automatically by using Proxy
// So for performance, if you need to change the data many times at once
// you can use db.getData() to get a copy of data
// Of course, you can give the class { realtimeUpdate: false } to the third argument
// to prevent the program from updating the JSON file automatically

console.log(db.data) // Output: { test: [ 1 ] }
  1. Don't worry if you change the type of T

The program will automatically update the content of the JSON file

If the JSON file is exist, the program will compare the content of the JSON file with data you give.

The exist data of the JSON file will take the place of data you give

and the non-exist data of the JSON file will use the default data which you give.

Advanced usage

Update the data of JSON file manually

If you change the content of JSON file and you want to get the latest content, use db.read() or db.readSync() to get the latest content.

const ConciseDb = require('concisedb')
const path = require('path')

const db = new ConciseDb(path.join(__dirname, 'db.json'), { test: [] })

console.log(db.data)
// Try changing the content of JSON file
setTimeout(() => {
  db.readSync()
  console.log(db.data)
}, 5000)
db.read()
import ConciseDb from 'concisedb'
import { join } from 'path'

interface Database {
  test: number[]
}

const db = new ConciseDb<Database>(join(__dirname, 'db.json'), { test: [] })

console.log(db.data)
// Try changing the content of JSON file
setTimeout(() => {
  db.readSync()
  console.log(db.data)
}, 5000)

Async and Sync APIs

Here are three APIs and they all support Async

  • db.read() and db.readSync()
  • db.write() and db.writeSync()
  • db.updateFile() and db.updateFileSync()

db.updateFile() and db.updateFileSync() are declared for compatibility. They are the same as db.write() and db.writeSync()

You might also like...

Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!

Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!

PostGraphile Instant lightning-fast GraphQL API backed primarily by your PostgreSQL database. Highly customisable and extensible thanks to incredibly

Jan 4, 2023

The JavaScript Database, for Node.js, nw.js, electron and the browser

The JavaScript Database, for Node.js, nw.js, electron and the browser

The JavaScript Database Embedded persistent or in memory database for Node.js, nw.js, Electron and browsers, 100% JavaScript, no binary dependency. AP

Jan 2, 2023

Node.js client for the Aerospike database

Aerospike Node.js Client An Aerospike add-on module for Node.js. The client is compatible with Node.js v8.x, v10.x (LTS), v12.x (LTS), and v14.x (LTS)

Dec 30, 2022

Common Database Interface for Node

database-js Wrapper for multiple databases with a JDBC-like connection Database-js implements a common, promise-based interface for SQL database acces

Dec 3, 2022

jSQL is a locally instantiated database for Node.js

jSQL is a locally instantiated database for Node.js. It provides the functionalities of a database, unique to a single project, meaning that no configuration from one project will affect another one.

Mar 7, 2022

The Blog system developed by nest.js based on node.js and the database orm used typeorm, the development language used TypeScript

 The Blog system developed by nest.js based on node.js and the database orm used typeorm, the development language used TypeScript

考拉的 Nest 实战学习系列 readme 中有很多要说的,今天刚开源还没来及更新,晚些慢慢写,其实本人最近半年多没怎么写后端代码,主要在做低代码和中台么内容,操作的也不是原生数据库而是元数据Meta,文中的原生数据库操作也当作复习下,数据库的操作为了同时适合前端和Node开发小伙伴,所以并不是很

Dec 22, 2022

a Node.JS script to auto-import USB drives that are attached to a computer. Use it to turn your NAS into a smart photo / file importer.

File Vacuum 5000 ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ WARNING: This script is designed to manipulate files on both an external drive and another specif

Jan 10, 2022

Fast File is a quick and easy-to-use library to convert data sources to a variety of options.

Fast File is a quick and easy-to-use library to convert data sources to a variety of options.

Fast File Converter The Express.js's Fast File Converter Library Fast File Converter Library is a quick and easy-to-use library to convert data source

Nov 16, 2022

🔄 A realtime Database for JavaScript Applications

🔄 A realtime Database for JavaScript Applications

RxDB A realtime Database for JavaScript Applications RxDB (short for Reactive Database) is a NoSQL-database for JavaScript Applications like Websites,

Dec 31, 2022
Releases(v1.0.1)
Owner
LKZ烂裤子
I'm a salted fish. Admire @YunYouJun
LKZ烂裤子
Realm is a mobile database: an alternative to SQLite & key-value stores

Realm is a mobile database that runs directly inside phones, tablets or wearables. This project hosts the JavaScript versions of Realm. Currently we s

Realm 5.1k Jan 3, 2023
A wrapper for abstract-leveldown compliant stores, for Node.js and browsers.

levelup Table of Contents Click to expand levelup Table of Contents Introduction Supported Platforms Usage API Special Notes levelup(db[, options[, ca

Level 4k Jan 9, 2023
⚡️ lowdb is a small local JSON database powered by Lodash (supports Node, Electron and the browser)

Lowdb Small JSON database for Node, Electron and the browser. Powered by Lodash. ⚡ db.get('posts') .push({ id: 1, title: 'lowdb is awesome'}) .wri

null 18.9k Dec 30, 2022
AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Andrey Gershun 6.1k Jan 9, 2023
DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB database, such as: connecting to the database, executing scripts, calling functions, uploading variables, etc.

DolphinDB JavaScript API English | 中文 Overview DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB

DolphinDB 6 Dec 12, 2022
Persisted global stores for Alpine 3.x.

✨ Help support the maintenance of this package by sponsoring me. Fern Persisted global stores for Alpine 3.x. Installation Since Fern directly extends

Ryan Chandler 25 Dec 15, 2022
mini-stores - 小程序多状态管理库,支持微信/支付宝/钉钉/百度/字节/QQ/京东等小程序,小巧高性能,新老项目都可使用。

mini-stores - 小程序多状态管理 前言 安装 API 使用 创建store 创建页面 创建组件 视图上使用 更新状态 使用建议 快捷链接 前言 公司好几款产品使用钉钉小程序开发,和其他平台小程序一样,都没有官方实现的状态管理库,用过redux、vuex、mobx等状态管理库的前端小伙伴都

linjc 104 Dec 27, 2022
🔥 Dreamy-db - A Powerful database for storing, accessing, and managing multiple database.

Dreamy-db About Dreamy-db - A Powerful database for storing, accessing, and managing multiple databases. A powerful node.js module that allows you to

Dreamy Developer 24 Dec 22, 2022
Database in JSON, fast and optimize

?? Database-Dev ?? DevNetwork#2103 ?? V 1.0.0 ?? Dependence Libs use ?? NodeJs V 16.14.2 (NodeJs) ?? fs (nodeFS) ?? Use libs import the file in your p

DevNetwork™️ 3 Apr 21, 2022
A Node.js library for retrieving data from a PostgreSQL database with an interesting query language included.

RefQL A Node.js library for retrieving data from a PostgreSQL database with an interesting query language included. Introduction RefQL is about retrie

Rafael Tureluren 7 Nov 2, 2022