0

i'm a beginner, i start to use compoudjs and i use jungglingdb for the database and the module jungglung-postgres. my question is, how can i add constraint to created tables? i try this var User = describe('User', function () { property('firstname', String); property('lastname', String); property('password', String,{ limit: 50); property('email', String {unique:true}); property('approved', Boolean); set('restPath', pathTo.users); }); but its not working

please help. tanks

Sam_al
  • 1
  • 1

1 Answers1

0

well i found a solution which is:

in the file nodes_modules/jugglingdb-postgres/lib/prostgres.js change the "datatype(p)" function to this by adding constraints for example:

    function datatype(p) {
 var q='';
if(p.unique!= undefined && p.unique)
{     q=' unique ';
 console.log(typeof(p.unique));
//
}
if(p.primaryKey!=undefined &&p.primaryKey)
{
    q=' primary key ';
}
if(p.notNull!=undefined &&p.notNull)
{
    q=' not null ';
}
if(p.check!=undefined )
{   //il faut definire manualement la condition de verification 
    q=' check('+p.check+') ';
    console.log(typeof(p.check));
}
if(p.constraintline!= undefined)
    q= ' '+p.constraintline;
if(p.constraint!= undefined)
    q= ' ,constraint '+p.constraint;
switch (p.type.name) {
    default:
    case 'String':
    case 'JSON':
    return 'varchar'+q;
    case 'Text':
    return 'text' +q;
    case 'Number':
    return 'integer' + q;
    case 'Date':
    return 'timestamp' + q;
    case 'Boolean':
    return 'boolean' + q;
}};
Sam_al
  • 1
  • 1