Reputation: 2776
With knex,I have this query:
this.knex(this.table)
.where(this.column_data, data)
.where("archive", 1)
I want to check if this.table has a column named 'archive', so I should use the 'hasColumn' method
How use schema.hasColumn(this.table, 'archive') in the previous query
Upvotes: 2
Views: 4421
Reputation: 2776
I resolved this:
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 => {
.....
});
Upvotes: 4