Home

Awesome

Driver Postgresql for Blockbase

Compatible with Blockbase Framework

Travis Blockbase

Version

v1.0.17

How to install ?

$ npm i --save blockbase-postgresql

Then add to your config/{env}.yml the following instructions depending of your system

dbms : postgresql
postgresql :
    host : localhost
    user : johndoe
    password :
    port : 5432
    database : yourdatabase

Postgresql driver also supports npm pg options, and implements connection Pooling

How to use ?

When you configure mysql as your dbms, Blockbase automatically binds the driver to the models with the basic methods. Such as read/save/update/delete etc.

Basic usage
//myController.js
module.exports = (app) => {
    cont Logger = app.drivers.logger
    const User = app.models.user

    return {
        async foo(req, res){

            let user = new User({id: 25})
            try {
              user = await user.read()

              //do stuff..

              res.send(user.expose('public'))
            catch (e) {
                Logger.error('foo', e)
                res.status(500).send({error :e})
            }
        }
    }
}
Standalone

The driver can be called inside your controller/models etc..

const mysql = app.drivers.mysql

let q = `SELECT * FROM users`
try {
  let result = await mysql.execute(q, [])
...
Within a controller :
//myController.js
module.exports = (app) => {
    const mysql = app.drivers.mysql

    return {
        async foo(req, res){
            //Do something with mysql
    ...
Within a model :
//myModel.js
module.exports = (app) => {
    const Model = app.model._model

    return class MyModel extends Model {
        constructor(data){
            super({type: 'user'})
            if(data) this.data = data
        }

        async foo(bar){
            let q = `SELECT * FROM ${this.params.type}`

            try {
                //this.client is binded to mysql
                return await this.client.execute(q, [])
            }
            catch(e) {
                throw e
            }
        }
    }
}

Methods

Blockbase-mysql driver implements the following methods :

Run tests

Blockbase has some unit tests (with Mocha) written run them often !

$ npm test

License

(Licence MIT) Coded by Blacksmith

Free Software, Hell Yeah!