0.1.10 • Published 10 years ago

json-db-lib v0.1.10

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

json-db-lib

Database library for lightweight databases based on JSON files.

Installation

Terminal

npm install json-db-lib

Usage

...
var db = require ('json-db-lib');
...

Functions

connect

connect( path )

It set the work directory .The path argument is the physical directory where the database json files will be saved.

load

load( table, init )

This function load or create a table json file in the working directory. The table argument is the name of your json data table. The init argument can takes two initializations: to initialize an collection set the init param to [], to initialize an object just set the init param to {}.

insert

insert( table, obj )

This function add a new object (obj) in the collection (table).

select

select( table, query, values )

The select function returns a vector with of the collection table that match with the search query, the query param looks like "user == :user AND password == :password", and the values param is an object key: value, the keys must be equal to the query variables preceded by :

like

like( table, key, value )

The like function returns all rows that contains value in the column key

between

between( table, key, value1, value2 )

between function returns all elements in the collection table that are in the range value1 <= X <= value2 X is a value of column key

update

update( table, obj, find )

This function update with obj the elements that match with the search criteria contained in find object into collection table.

delete

delete( table, query, values )

The delete function remove all objects that match with the query criteria like a select function.

save

save()

It save the collection into json file.

Example

...
var db = require('json-db-lib');
db.connect( './data' );
db.load( 'user', [] );
var user = {
  login: 'lorem',
  pass: 'access',
  name: 'Loremso Ipsumo',
  email: 'loremso@example.com'
};
db.insert( 'user', user );
...

Credits

This project has been created by Raúl Salvador Andrade and is sponsored by WA Technologies

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.5

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago