Skip to content

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

License

Notifications You must be signed in to change notification settings

sidharthmenon/Simple-File-DB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published