【问题标题】:how we can add constraint ti our shema "compoudjs / jungglingdb"我们如何为我们的 shema“化合物/杂耍”添加约束
【发布时间】:2013-03-14 09:58:13
【问题描述】:

我是初学者,我开始使用 compoudjs,我使用 jungglingdb 作为数据库和模块 jungglung-postgres。 我的问题是,如何向创建的表添加约束? 我试试这个 var User = describe('User', function () { 属性('名字',字符串); 属性(“姓氏”,字符串); 属性('密码',字符串,{限制:50); 属性('电子邮件',字符串 {unique:true}); 属性(“已批准”,布尔值); set('restPath', pathTo.users); }); 但它不起作用

请帮忙。 坦克

【问题讨论】:

    标签: compoundjs


    【解决方案1】:

    我找到了一个解决方案:

    在文件 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;
    }};
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-19
      相关资源
      最近更新 更多