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

Add support for compound UNIQUE and PRIMARY KEY constraints #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

@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