1.1.4 • Published 8 years ago

nevermind-collections v1.1.4

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

Nevermind Collections

Contents

Foreword

It has always been a pain while starting the back-end of a project especially if you are prototyping. nevermind-collections is a part of an ongoing project called NevermindJS.

You can easily connect nevermind-collections to your database and turn it to a RESTful api in no time! If you would not like to install a database to your server or want your backend to be standalone simple use nedb adapter which is built on a flat file database. All your collections will be kept in json files.

Please feel free to contribute and let me know about the features you may need for a better nevermind-collections!

Project can also be found on Github

@kucukkanat

Server

To Create a Server

var Nevermind = require('nevermind-collections')

var Server = new Nevermind(8080)
//Initiate the database
Server.nedb()
Server.eventListener.on("insert:users",function(e){
  console.log(e,' Inserted!')
})

For Mysql Developers

If you are using mysql adapter initiate connection with :

    Server.mysql({
        host     : 'localhost',
        user     : 'me',
        password : 'secret',
        database : 'my_db'
      })

For mysql developers /collection paths are not exposed to clients since client can run any query due to security reasons. Mysql developers can add routes and set the actions for each endpoint themselves like :

    Server.Router.get('/users',function(req,res){
      Server.Adapter.table('users').query('SELECT * FROM users')
      .then(function(err,rows){
        res.send(rows)
        })
      })

Adding more routes

The server instance also exposes express application so that user can add her own routes. (Here we encourage female developers, no typo ;) )

Server.Router.get('/test',function(req,res){
  res.send('Hello world!')
  })

Using database on your own (Only works with nedb adapter!)

Get major people :

  Server.Adapter.table('someTableName').find({age:{$gt:18}})
  .then(function(err,result){
    //Do something with the result
  })

Insert something to table :

  Server.Adapter.table('someTableName').insert({productName:"Armchair":price:25},function(err,result){
    //Do something with the result
  })

Register and login (Only works with nedb!)

First you need to register an account :

post /register

{username:"",password:"",email:""}

Then login to acquire a token :

post /login

{username:"",password:""}


It is very important that you keep the token so you can use /collection/* endpoints !!!


Restful Api Endpoints (Only works with nedb!)

POST /collection/insert/:collectionName

Parameters :
{
  "item":{}
}

POST /collection/update/:collectionName

Parameters :
{
  "item":{},
  "query":{}
}

POST /collection/remove/:collectionName

Parameters :
{
  "query":{}
}

POST /collection/find/:collectionName

Parameters :
{
  "query":{}
}
TO-DO
  • Add event emitters for each action
  • Add before event emitter
  • Documentation for server instance
  • Adapters for different databases
    • MySQL
    • MongoDB
    • NedDB