Git Product home page Git Product logo

lite-web-db's Introduction

lite-web-db

This is a lite weight JSON Data Base System for storing simple data.

Underneath it manages a series of JSON files that store information for your application. In order to provide a lite weight system, we removed many common security features found in other Data Base Systems. What it lacks in native security, however, lite-web-db makes up for in simplicity and efficiency.

Setup

const manager = require('lite-web-db');
manager.STORAGE_PATH = "/path/to/files";
const db = manager.startup('database-name');

Saving data

manager.saveToDisk(db);
manager.shutdown(db);        // shutdown with AutoSave
manager.shutdown(db, false); // shutdown and do not save

Usage

const table = db.getTable('table-name');

Querying

Test against a value
const search = { key: "index", is: 1 };
var matchingRows = table.query(search);
Test against a set of values
const search = { key: "index", includes: [1,4] };
var matchingRows = table.query(search);
Test against a predicate function
const search = { key: "index", predicate: function (value) {
  return (val % 2 == 0); // Returns true if value is odd
}};
var matchingRows = table.query(search);
Negating a test
const search = { key: "index", is: 1, not: true };
var matchingRows = table.query(search);
var allRows = table.query();

Inserting

// insert one row
const newRow = { number: 1, english: "one", spanish: "uno" };
table.insert(newRow);

// insert multiple rows
const moreRows = [
  { number: 2, english: "two",   spanish: "dos"    },
  { number: 3, english: "three", spanish: "tres"   },
  { number: 4, english: "four",  spanish: "quatro" }
];
table.insert(moreRows);
table.query(); /* RETURNS ===> [
  { index: 1, number: 1, english: "one",   spanish: "uno"    },
  { index: 2, number: 2, english: "two",   spanish: "dos"    },
  { index: 3, number: 3, english: "three", spanish: "tres"   },
  { index: 4, number: 4, english: "four",  spanish: "quatro" }
] */

Updating

const test = { key: "index", is: 4 };
const newData = { english: "FOUR" };
table.update(newData, test);
var toUpper = function (value) {
  return value.toUpperCase();
};
table.update({ english: toUpper, french: toUpper });

Deleting

// delete matching rows
const removeSearch = { key: "index", is: 4 };
table.delete(removeSearch);

// delete all the data in the table
table.delete();  
table.restoreLastDeletion();

lite-web-db's People

Watchers

James Cloos avatar

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.