Add support for compound `UNIQUE` and `PRIMARY KEY` constraints
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.
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(...)!