0

私は初心者です。compoudjs を使い始め、データベースとモジュール jungglung-postgres に jungglingdb を使用しています。私の質問は、作成したテーブルに制約を追加するにはどうすればよいですか? 私はこれを試してください 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); }); しかし、それは機能していません

助けてください。戦車

4

1 に答える 1

0

さて、私は次の解決策を見つけました:

ファイル nodes_modules/jugglingdb-postgres/lib/prostgres.js で、たとえば次のような制約を追加して、「datatype(p)」関数をこれに変更します。

    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;
}};
于 2013-04-19T08:30:22.117 に答える