2017-05-26 82 views
0

随着knex,我有这个疑问:如何使用hasColumn与其中knex条款

this.knex(this.table) 
      .where(this.column_data, data) 
      .where("archive", 1) 

我想检查this.table有一个名为“档案”一栏,所以我应该使用' hasColumn”的方法

如何使用schema.hasColumn(this.table, '在前面的查询

回答

1

我解决了这个压缩文件'):

this.knex.schema.hasColumn(this.table, "archive") 
      .then(exists => { 
       if (exists){ 
        this.knex(this.table).where("archive", 1); 
       } 
       this.knex(this.table) 
        .where(this.column_data, data) 
        .then((datas)=> { 
        ........ 
        }); 
      }).catch(err => { 
       ..... 
      });