簡體   English   中英

如何在knex中的has子句中使用hasColumn

[英]How can I use hasColumn with where clause in knex

使用knex,我有以下查詢:

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

我想檢查this.table是否有一個名為“ archive”的列,所以我應該使用“ hasColumn”方法

如何在上一個查詢中使用schema.hasColumn(this.table,'archive')

我解決了這個問題:

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 => {
                .....
            });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM