Skip to content
Small and simple noSQL-like database module for NodeJS applications.
JavaScript
Branch: master
Clone or download
luxwarp Version: 0.2.2
Changes:
lociDB database folder is now saved at users default appData folder instead of the application root folder.
You can also decide you self where to store it and what name it should have. See wiki.
Fix of some typos and styling.
Latest commit 6718adb May 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore New version: 0.2.1 May 15, 2019
LICENSE New version: 0.2.1 May 15, 2019
README.md Version: 0.2.2 May 18, 2019
index.js
package-lock.json Version: 0.2.2 May 18, 2019
package.json Version: 0.2.2 May 18, 2019
test.js Version: 0.2.2 May 18, 2019

README.md

lociDB

JavaScript Style Guide

Intro

Small and simple noSQL-like database module for NodeJS applications.

This module lets you store an array of objects into simple plain text files as a JSON string. You dont need to stringify your objects first, lociDB does that for you (see usage below).

This noSQL-like database is perfect for your small NodeJS and Electron applications where you maby want to store some kind of user settings, to-do list etc for example.

See our change log in the wiki.

If you planing on storing >100MB of data this module is not for you.

Install

npm install --save locidb

Usage

const LociDB = require('locidb')                        // Import the module.
const db = new LociDB()                                 // Create an instance of lociDB. A lociDB folder is created per auto in users appData folder.
// const db = new LociDB('/path/to/destination', 'mycooldb')  // You can also decide your self where to store lociDB database, table files and what name it should have.
// const db = new LociDB(undefined, 'mycooldb')               // Create a lociDB database folder at default location but change the name.
// const db = new LociDB(app.getPath('userData'), 'mycooldb') // For electron app developer. A lociDB database folder is created per auto inside you app config folder which is in users default appData folder.

let user = {                                            // This is three example objects.
  name: 'Mikael',
  age: 27,
  city: 'Bohus',
  country: 'Sweden'
}

let user2 = {
  name: 'Kalle',
  age: 27,
  city: 'Nol',
  country: 'Norway'
}

let settings = {
  fontSize: 13,
  color: '#000',
  active: false
}

console.log(db.listTables())                            // First list tables to se if it exists any already.

db.set('users', user)
db.set('settings', settings)                            // This will overwrite any data in the table and insert the value instead.

db.insert('users', user2)                               // Insert the object to the table at the end.

console.log(db.countRows('users'))                      // Count how many rows there is in a table.

console.log(db.get('users'))                            // Get all rows in the table as an array of objects and print it.
console.log(db.get('settings'))

console.log(db.getRows('users', 'name', 'Mikael'))      // Get all rows in a table matching a key and a value as an array of objects.

console.log(db.dropRows('users', 'name', 'Mikael'))     // Drop/delete specific rows in a table. Returns a number of total rows deleted.
db.dropTable('settings')                                // Drop/delete a specific table. Returns true if a delete was made of false if not.
db.dropAll();                                           // Drop/deletes all tables. Use only if you know what you doing.

Testing

If you want to try some functions before using this module in your applications you can use the test.js file located in the root folder of the module and then run the file in your terminal with the command node ./test.js

License

ISC - © Copyright Mikael Carlsson

Note

Feel free to contribute the way you want.

You can’t perform that action at this time.