mongo-sql icon indicating copy to clipboard operation
mongo-sql copied to clipboard

Add better syntax for non-parameterized values in condition builder

Open jrf0110 opened this issue 12 years ago • 2 comments

The current syntax is to wrap the value in dollars. I think maybe making this double dollar would be good as postgres already supports this. However, It fucks up your value. It becomes a chore to check query.joins.group.id == '$otherTable.id' rather than simply query.joins.group.id === 'otherTable.id'

I thought about making a global property that will say, hey any descendents of me do not get parameterized. That syntax would look like:

var query = {
  type: 'select'
, table: ['users', 'groups']
, where: {
    $: { 'users.id': 'groups.userId' }
  , 'groups.name': 'admin'
  }
};

While this cleans the syntax a bit, it becomes just as difficult, if not harder to reason about. You would be like, query.where['users.id'] thinking you would find it.. but you don't know what objects are going to have a $ property.

Maybe we could have a completely separate where clause:

var query = {
  type: 'select'
, table: ['users', 'groups']
  // Not parameterized
, $where: {
    'users.id': 'groups.userId'
  }
  // Parameterized
, where: {
    'groups.name': 'admin'
  }
};

jrf0110 avatar Jun 07 '13 03:06 jrf0110

Maaayyyybe something like:

var query = {
  type: 'select'
, table: ['users', 'groups']
, where: {
    'users.id': mosql.$('groups.userId')
  , 'groups.name': 'admin'
  }
};

jrf0110 avatar Feb 07 '14 16:02 jrf0110

Or:

where: {
    'users.id': { $eqfield: 'groups.userId' }
}

Meaglin avatar May 31 '15 14:05 Meaglin