npm

This package has been deprecated

Author message:

no longer maintaining

eden-postgres

0.0.32 • Public • Published

PostGreSQL

DESCRIPTION

Build Status

General

Installation

npm install eden-postgres

Usage

var postgres = require('eden-postgres');

Methods


collection

 eden/postgres/collection collection(collection[1].user_email);

Returns collection

Parameters

  1. collection[1].user_email - function

Returns

eden/postgres/collection

Example

Code
      database.collection('eden_users')
        .add({})
        .add({})
        .setUserName('Bobby2')
        .setUserEmail('bobby2@gmail.com')
        .setUserFacebook(123)

postgres().collection[1].user_name;
postgres().collection[1].user_email;
postgres().collection[1].user_facebook;
Outputs
'Bobby2'
'bobby2@gmail.com'
123

connect

 this connect('eden_users');

Connects to the database

Parameters

  1. 'eden_users' - array - the connection options

Returns

this

Example

Code
postgres().connect('eden_users');
Outputs
'edenjs_test'

getConnection

 connection resource getConnection(edenjs_test);

Returns the connection object if no connection has been made it will attempt to make it

Parameters

  1. edenjs_test - array - connection options (database name)

Returns

connection resource

Example

Code
postgres().getConnection('edenjs_test');
Outputs
'edenjs_users'

getColumns

 this getColumns(eden_users, user_id, SELECT);

Returns the columns and attributes given the table name

Parameters

  1. eden_users - the name of the table

  2. user_id - name of schema

  3. SELECT - function - callback

Returns

this

Example

Code
postgres().getColumns('SELECT user_id FROM eden_users');
postgres().getColumns('SELECT user_name FROM eden_users');
postgres().getColumns('SELECT user_email FROM eden_users');
postgres().getColumns('SELECT user_facebook FROM eden_users');
Outputs
'user_id'
'user_name'
'user_email'
'user_facebook'

getRow

 this getRow(eden_users, user_email, 'bob@gmail.com', select);

Returns a 1 row result given the column name and the value

Parameters

  1. eden_users - string - table name

  2. user_email - string - name of schema (column name)

  3. 'bob@gmail.com' - string - row value in column user_email

  4. select - function - callback

Returns

this

Example

Code
database.getRow('eden_users', 'user_email', 'bob@gmail.com');
database.getRow('eden_users', 'user_email', 'dayle@gmail.com');
Outputs
'bobby'
null

insert

 eden/postgres/insert insert('blog_users');

Returns the insert query builder

Parameters

  1. 'blog_users' - string - table name to add columns and rows

Returns

eden/postgres/insert

Example

Code
var query = database.insert('blog_users')
        .set('user_name', 'chris')
        .set('user_age', 21)
        .getQuery();

query = database.insert('blog_users')
        .set({user_name: 'chris', user_age: 21})
        .getQuery();

query = database.insert('blog_users')
        .set('user_name', 'chris', 0)
        .set('user_age', 21, 0)
        .set('user_name', '?', 1)
        .set('user_age', 22, 1)
        .getQuery();

query = database.insert('blog_users')
        .set({user_name: 'chris', user_age: 21})
        .set({user_name: 'dan', user_age: 22}, 1)
        .getQuery();
Outputs
'INSERT INTO "blog_users" ("user_name", "user_age") VALUES (\'chris\', 21);'
'INSERT INTO "blog_users" ("user_name", "user_age") VALUES (\'chris\', 21);'
'INSERT INTO "blog_users" ("user_name", "user_age") VALUES (\'chris\', 21), (?, 22);'
'INSERT INTO "blog_users" ("user_name", "user_age") VALUES (\'chris\', 21), (\'dan\', 22);'

insertRow

 this insertRow('eden_users', user_name, Array|bool|null, Function);

Inserts data into a table and returns the ID

Parameters

  1. 'eden_users' - string - table

  2. user_name - object - setting

  3. array|bool|null

  4. function - callback

Returns

this

Example

Code
database.insertRow('eden_users', {
        user_name: 'bob',
        user_email: 'bob@gmail.com',
        user_facebook: 123
      }, function(error, rows, meta));

postgres().insertRow(meta.oid > 1);
Outputs
true

insertRows

 this insertRows(eden_users, user_name, Array|bool|null, Function);

Inserts multiple rows into a table

Parameters

  1. eden_users - string - table

  2. user_name - object - settings

  3. array|bool|null

  4. function - callback

Returns

this

Example

Code
    database.insertRows('eden_users', [{
        user_name: 'bob',
        user_email: 'bob@gmail.com',
        user_facebook: 123
      }, {
        user_name: 'chris',
        user_email: 'bob@gmail.com',
        user_facebook: 312
      }], function(error, rows, meta));

postgres().insertRows(meta.rowCount);
Outputs
2

model

 eden/postgres/model model(eden_users);

Returns model

Parameters

  1. eden_users - string (table name to set row in column)

Returns

eden/postgres/model

Example

Code
    database.model('eden_users')
        .setUserName('Bobby')
        .setUserEmail('bobby@gmail.com')
        .setUserFacebook(123)
        .save(function(error, model, meta));

postgres().model(null);

    model.setUserName('Billy').save(function(error, model, meta));

postgres().model(error);
Outputs
error
null

query

 this query(eden_users, all/*, select);

Queries the database

Parameters

  1. eden_users - string - query

  2. all/* - array - binded value

  3. select - function - callback

Returns

this

Example

Code
  database.query('SELECT * FROM eden_users', function(error, rows, meta));

postgres().query(meta.rows.length > 0);
Outputs
true

remove

 eden/postgres/delete remove('user_id = 1');

Returns the delete query builder

Parameters

  1. 'user_id = 1' - string (column and row value to be remove)

Returns

eden/postgres/delete

Example

Code
var query = database
        .remove('blog_users')
        .where('user_id = ?')
        .getQuery();

query = database
        .remove('blog_users')
        .where(['user_id = ?', 'user_name = ?'])
        .getQuery();

query = database
        .remove('blog_users')
        .where('user_id = ?')
        .where('user_name = ?')
        .getQuery();
Outputs
'DELETE FROM "blog_users" WHERE user_id = ?;'
'DELETE FROM "blog_users" WHERE user_id = ? AND user_name = ?;'
'DELETE FROM "blog_users" WHERE user_id = ? AND user_name = ?;'

removeRows

 this removeRows(eden_users, 'user_email = ?', Function);

Removes rows that match a filter

Parameters

  1. eden_users - string - table name

  2. 'user_email = ?' - array - filter

  3. function - callback

Returns

this

Example

Code
database.removeRows('eden_users', 
      [['user_email = ?', 'bob@gmail.com']], 
      function(error, rows, meta));

postgres().removeRows(typeof meta === 'object');
Outputs
true

select

 eden/postgres/select select('*'/all);

Returns the select query builder

Parameters

  1. '*' / all - string (to get the respective column)

Returns

eden/postgres/select

Example

Code
var query = database.select('*')
        .from('blog_users')
        .innerJoin('blog_post', 'post_user=user_id', false)
        .where('user_name = ?')
        .sortBy('user_name')
        .groupBy('user_id')
        .limit(1, 2)
        .getQuery();

query = database.select('*')
        .from('blog_users')
        .leftJoin('blog_post', 'post_user=user_id', false)
        .where('user_name = ?')
        .sortBy('user_name', 'DESC')
        .groupBy('user_id')
        .limit(1, 2)
        .getQuery();

query = database.select('*')
        .from('blog_users')
        .rightJoin('blog_post', 'post_user=user_id', false)
        .where('user_name = ?')
        .sortBy('user_name')
        .getQuery();

query = database.select('*')
        .from('blog_users')
        .outerJoin('blog_post', 'post_user')
        .where('user_name = ?')
        .groupBy('user_id')
        .limit(1, 2)
        .getQuery();
Outputs
'SELECT * FROM blog_users INNER JOIN blog_post ON (post_user=user_id) '
      + 'WHERE user_name = ? GROUP BY "user_id" ORDER BY "user_name" ASC OFFSET 1 LIMIT 2;'

'SELECT * FROM blog_users LEFT JOIN blog_post ON (post_user=user_id) '
      + 'WHERE user_name = ? GROUP BY "user_id" ORDER BY "user_name" DESC OFFSET 1 LIMIT 2;'

'SELECT * FROM blog_users RIGHT JOIN blog_post ON (post_user=user_id) '
      + 'WHERE user_name = ? ORDER BY "user_name" ASC;'

'SELECT * FROM blog_users OUTER JOIN blog_post USING (post_user) '
      + 'WHERE user_name = ? GROUP BY "user_id" OFFSET 1 LIMIT 2;'

search

 eden/postgres/search search('user_name = ?');

Returns search

Parameters

  1. 'user_name = ?' - function (to get the respective row data)

Returns

eden/postgres/search

Example

Code
  database.search('eden_users').getRows(function(error, rows));
postgres().search(typeof rows.length);

  database.search('eden_users')
      .addFilter('user_name = ?', 'Christian Blanquera')
      .getRow(function(error, row, meta));
postgres().search(row.user_email);

  database.search('eden_post')
      .innerJoinOn('eden_users', 'post_user=user_id')
      .getRows(function(error, rows));
postgres().search(typeof rows.length);

  database.search('eden_post')
      .innerJoinOn('eden_users', 'post_user=user_id')
      .filterByUserName('Christian Blanquera')
      .getRow(function(error, row, meta));
postgres().search(row.user_email);

  database.search('eden_post')
      .innerJoinOn('eden_users', 'post_user=user_id')
      .filterByUserName('Christian Blanquera')
      .sortByUserId('DESC')
      .getRows(function(error, rows, meta));
postgres().search(typeof rows.length);

  database.search('eden_post')
      .innerJoinOn('eden_users', 'post_user=user_id')
      .filterByUserName('Christian Blanquera')
      .sortByUserId('DESC')
      .getCollection(function(error, collection, meta));
postgres().search(collection[0].getUserName());

  database.search('eden_post')
      .innerJoinOn('eden_users', 'post_user=user_id')
      .filterByUserName('Christian Blanquera')
      .sortByUserId('DESC')
      .getCollection(function(error, collection, meta));
          
          collection.setUserFacebook(321).save(function(error, collection, meta));
postgres().search(collection[0].getUserFacebook());

  database.search('eden_post')
      .innerJoinOn('eden_users', 'post_user=user_id')
      .filterByUserName('Christian Blanquera')
      .sortByUserId('DESC')
      .getModel(function(error, model, meta));
postgres().search(model.getUserName());

  database.search('eden_post')
      .innerJoinOn('eden_users', 'post_user=user_id')
      .filterByUserName('Christian Blanquera')
      .sortByUserId('DESC')
      .getModel(function(error, model, meta));

          model.setUserFacebook(10204676425696496).save(function(error, collection, meta));
postgres().search(model.getUserFacebook());
Outputs
'number'

'cblanquera@gmail.com'

'number'

'cblanquera@gmail.com'

'number'

'Christian Blanquera'

321

'Christian Blanquera'

10204676425696496

setRow

 this setRow(String, String, String, Object, Function);

Sets only 1 row given the column name and the value

Parameters

  1. string - table

  2. string - name

  3. string - value

  4. object - setting

  5. function - callback

Returns

this

Example

Code
postgres().setRow();
Outputs
RESULTS

update

 eden/postgres/update update(String);

Returns the update query builder

Parameters

  1. string

Returns

eden/postgres/update

Example

Code
    var query = database.update('blog_users')
        .set('user_name', 'chris')
        .set('user_age', 21)
        .where('user_id = ?')
        .where('user_name = ?')
        .getQuery();
postgres().update(query);

    query = database.update('blog_users')
        .set({user_name: 'chris', user_age: 21})
        .where(['user_id = ?', 'user_name = ?'])
        .getQuery();
postgres().update(query);
Outputs
'UPDATE "blog_users" SET "user_name" = \'chris\', "user_age" = 21 WHERE user_id = ? AND user_name = ?;'
'UPDATE "blog_users" SET "user_name" = \'chris\', "user_age" = 21 WHERE user_id = ? AND user_name = ?;'

updateRows

 this updateRows('eden_users', Object, Array, Array|bool|null, Function);

Updates rows that match a filter given the update settings

Parameters

  1. 'eden_users' - string - table

  2. object - setting

  3. array - filter

  4. array|bool|null

  5. function - callback

Returns

this

Example

Code
database.updateRows('eden_users', {
        user_name: 'bobby'
      }, [['user_email = ?', 'bob@gmail.com']], function(error, rows, meta));

postgres().updateRows(meta.rowCount > 1);
Outputs
true

Readme

Keywords

Package Sidebar

Install

npm i eden-postgres

Weekly Downloads

4

Version

0.0.32

License

none

Last publish

Collaborators

  • archive_donotuse