【问题标题】:Adonis js Where Clauses not work. this code always returned value 0Adonis js Where 子句不起作用。此代码始终返回值 0
【发布时间】:2020-11-04 15:18:23
【问题描述】:

我正在尝试预订创建一个时间段并在两次时间值之间查找此代码始终返回值 0。

async store({request, auth, response}) {
let {uuid, start_timestamp, end_timestamp, price} = request.all();
try {
  let influencer = await auth.getUser();
  let avaliabelBookinSlot = await Database.from('booking_slots')
    .where('influencer_id', influencer.id)
    .where(function () {
      this
        .where(function () {
          this
            .where('start_timestamp', '>', start_timestamp)
            .where('start_timestamp', '<', end_timestamp)
        }).orWhere(function () {
          this
            .where('end_timestamp', '>', start_timestamp)
            .where('end_timestamp', '<', end_timestamp)
        })
    }).orWhere(function () {
      this
        .where('start_timestamp', '>', start_timestamp)
        .where('end_timestamp', '<', end_timestamp)
    })
  console.log(avaliabelBookinSlot.length)

}

【问题讨论】:

    标签: javascript node.js laravel knex.js adonis.js


    【解决方案1】:

    而不是你需要使用 where 和 Where 的地方

    this.where('start_timestamp', '>', start_timestamp).andWhere('end_timestamp', '<', end_timestamp)
    

    【讨论】:

      【解决方案2】:

      你可以尝试像这样使用 where 条件:

      await Database.from('booking_slots').where({
              {'start_timestamp', '>', start_timestamp},
              {'start_timestamp', '<', end_timestamp} });
      
          
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-09-12
        • 1970-01-01
        • 1970-01-01
        • 2018-09-22
        • 1970-01-01
        • 2017-09-05
        • 1970-01-01
        相关资源
        最近更新 更多