jrf0110 / dirac

A Node Postgres DB layer built with MoSQL
http://dirac.j0.hn
6 stars 2 forks source link

v1.0.0 Release #54

Open jrf0110 opened 9 years ago

jrf0110 commented 9 years ago

Easily composable factory based API:

var db = require('dirac')('postgres://localhost:5432/my_db?ssl=true');

// More specific
var db = require('dirac')
  .host('localhost')
  .port(5432)
  .ssl(true)
  .db('my_db');

// Use middleware for instance
db = require('dirac')('...')
  .use( db.relationships() )
  .use( myCustomMiddlewares );

// Query by strings
db.query('select * from users where id = $1', [10])
  .then( function( results ){
    // Promised based API or node-style callbacks
  });

db.query({
  type: 'select'
, table: 'users'
, where: { id: 10 }
}).then(...);

// Setup dals
db.users = db.dal({ ... });

// Initiate query objects
var query = db.users.find()
  .where({ id: 10 })
  .or({ id: 12 })
  .one({ table: 'region' })
  .many({ table: 'orders' })

query.exec().then( ... );
jrf0110 commented 9 years ago

Arbitrary query composition:

var q1 = dirac.query();

q1.table('orders')
  .where({ status: 'submitted' })
  .order(['id desc'])
  .limit(30);

db.users.find()
  .where.({ id: 10 })
  .many( q1 )

dirac.query() would simply return a fancy mosql object with setters/getters. If it's just called from the base dirac namespace, no connection string or middleware will be associated to it

jrf0110 commented 9 years ago

Place a bigger emphasis on the Relationships helpers

jrf0110 commented 8 years ago

Stream support with https://github.com/brianc/node-pg-query-stream

db.orders().find()
  .where({ ... })
  .many({ table: 'order_items', alias: 'items' })
  .pipe( res );

Where .pipe would automatically execute the query with a streaming client.