Giter Club home page Giter Club logo

simple-file-db's Introduction

Simple-File-DB

Simple file based database in nodejs. Data is stored as json files.

SQL FileDB
Table Collection
Row Document

How to use

currently not available in npm you have to clone manually.

1. require the package

var db = require("./db") //change accordingly

2. define variable to represent database

var database = new db();

Existing database is referenced or if it doesnot exsist new database is created

default location of database current directory (./)

default name of database is .data

to define custom location and name for database use

var database = new db(dbname, dbpath);

3. define variable to represent table

var userTable = database.collection("users")

Existing table is referenced or if it doesnot exsist new table is created

4. insert data into table

row with autogenerated ID

userTable.add({name: "John", age: 25}).then(doc => console.log(doc));

row with custom ID

userTable.doc('john').set({name: "John", age: 23}).then(doc => console.log(doc));

5. retrive data

get all data from table

userTable.get().then(docs => console.log(docs));

get data based on condition

userTable.where("name", "==", "John").get().then(docs => console.log(docs));

multiple conditions

userTable.where("name", "==", "John").where("age", "==", 25).get().then(docs => console.log(docs));

6. Update data

replace entire data of row

userTable.doc('john').set({name: "John Doe"}).then(doc => console.log(doc));
//here only the name field will be remaining in the saved all other data in the row is lost

change existing data or add fields

userTable.doc('john').set({age: 30, location: "Canada"},{merge: true}).then(doc => console.log(doc));
//here name will remain unchanged age will be updated and location field will be added

::TODO::

  • Currently only = condition is checked in where more conditions need to be added

simple-file-db's People

Contributors

sidharthmenon avatar

Watchers

 avatar  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.