0.0.7 • Published 6 years ago

silly-nosql v0.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

@DEPRECATED

This module won't get maintenance any more. It will remain here to provide it for those projects that use it, but that's all. As an alternative, we recommend to move to DocsOnFilesDB

Silly NoSQL (v0.0.6)

NoSQL database emulated with files. For small tests, not real stuff, of course, c'mon, don't be silly.

Installation

To install this module on your NodeJS project run this:

npm install silly-nosql --save

How to use

First of all, you need to create a directory where to store your data, as an example will conside a directory called db in the same direcory where you store your script.

Then use a cose like this:

'use strict';
//
// Importing requried library.
const path = require('path');
//
// Importing this library.
const snsql = require('silly-nosql');
//
// Getting the connections manager singleton.
const snsqlManager = snsql.manager;
//
// Getting a connection to our database (... the directory).
const myDB = snsqlManager.connect(path.join(__dirname, 'db'));
//
// Getting a table. If it doesn't exist, it will create it.
const myTable = myDB.table('my_table');
//
// Inserting an arbitrary object.
myTable.insert({
    name: 'John Doe',
    age: 20,
    address: {
        city: 'Some City',
        address: 'Some street 49'
    }
});
//
// Retrieving and prompting.
console.log('Results:', JSON.stringify(myTable.all()));

This should show you something like this:

Results: [{"name":"John Doe","age":20,"address:{"city:"Some City","address":"Some street 49"}}]

Objects and Methods

Follow this link for some documentation.

ExpressJS adapter

If you use ExpressJS you can use this to expose your tables as a RESTful API:

'use strict'
const path = require('path');
const express = require('express');
const snsql = require('silly-nosql');

const app = express();
const snsqlManager = snsql.manager;
const myDB = snsqlManager.connect(path.join(__dirname, 'db'));
const myTable = myDB.table('my_table');

// ... all your express setting

snsql.adapters.ExpressAdapter.adapat(app, myTable, {
    path: '/rest/v1'
});

// ... rest of your stuff

This will provide you with this endpoints:

  • GET /rest/vi/my_table
  • POST /rest/vi/my_table
  • GET /rest/vi/my_table/:id
  • PUT /rest/vi/my_table/:id
  • PATCH /rest/vi/my_table/:id
  • DELETE /rest/vi/my_table/:id

Licence

MIT © Alejandro Dario Simi

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago