Skip to content

Conversation

@brianc
Copy link
Contributor

@brianc brianc commented Jun 15, 2016

I'm not 100% sure this is the correct approach or if all the formatting is okay. This is a first crack at adding table constraints to support natural keys.

@brianc brianc force-pushed the table-constraints branch from 75c9bf4 to 8ad15ab Compare June 15, 2016 01:56
@jrf0110
Copy link
Member

jrf0110 commented Jun 15, 2016

This is perfect! And it made me remember some things that will make it more robust.

So, this lib needs to be refactored. There's too many concepts:

  • Query Types
  • Query Helpers
  • Conditional Helpers
  • Update Helpers
  • Action Helpers
  • Column Definition Helpers

When I first wrote MoSQL, I thought there'd be a unified helper interface, but as time went on, I ended up with more and more specialized helpers.

The Column Definition Helpers can assist us here:

var columnDefs = require('../../lib/column-def-helpers');

...

return Object
  .keys( constraints )
  .filter( function( k ){
    return columnDefs.has( k );
  })
  .map( function( k ){
    return columnDefs.get( k ).fn( constraints[ k ], values, query );
  })
  .reduce( function( result, constraint ){
    result.push( constraint );
    return result;
  }, [] )
  .join(', ')

I think that code would work I'm not sure. But my main point would be to use the column-def-helpers module and that will actually give you primary key(...), unique(...) and check(...)!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants