Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make interface more declarative #5

Merged
merged 10 commits into from
May 13, 2013
Merged

Make interface more declarative #5

merged 10 commits into from
May 13, 2013

Conversation

jrf0110
Copy link
Member

@jrf0110 jrf0110 commented May 12, 2013

Originally, mongo-pg and mongo-sql we're the same libraries. Mongo-Sql resembles the early muck of the imperative style:

find($query, options)

But this is no longer really needed. This is just a sql generator for JSON. Let's move to this syntax:

{
  type: 'select'

, columns: [ '*', 'extension.field1', 'extension.field2' ]

, tables: [ 'users', 'extension' ]

, joins: {
    leftJoin: { 
      extension: { id: 'extension.id' }
    }
  }

, where: {
    name: { $ilike: 'bob', $or: { $ilike: 'alice' } }
  , id: {
      $nin: {
        type: 'select'
      , columns: 'id'
      , table: 'otherUsers'
      , where: { someCondition: true }
      }
    }
  }

, limit: 100

, order: { id: 'desc' }

, groupBy: ['id', 'name']
}

Where each top-level property corresponds with a field in the base query:

select {fields} from {collections} {joins} {where} {limit} {order} {groupBy}

And each field also corresponds to a builder function.

In this way, you would be able to write custom query types more easily.

@jrf0110
Copy link
Member Author

jrf0110 commented May 7, 2013

Working on helper interface for building custom query types:

var builder = require('this_library_name');

builder.registerQueryType(
  'select products'
, 'select * from products {where} {limit} order by name desc'
);

builder.sql({
  type: 'select products'
, where: {
    name: { $ilike: 'Product Na' }
  }
, limit: 30
, offset: 60
});

@jrf0110
Copy link
Member Author

jrf0110 commented May 13, 2013

HAVE TO MERGE NOW TO SAVE STREAK

jrf0110 added a commit that referenced this pull request May 13, 2013
Make interface more declarative
@jrf0110 jrf0110 merged commit 54f6b0b into master May 13, 2013
@jrf0110 jrf0110 deleted the 5-imprv-new-syntax branch May 13, 2013 00:00
@lalitkapoor
Copy link
Contributor

👍 reason to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants