zoukankan      html  css  js  c++  java
  • thinkjs中自定义sql语句

    一直以为在使用thinkjs时,只能是它自带的sql语句查询,当遇到类似于这样的sql语句时,却不知道这该怎样来写程序,殊不知原来thinkjs可以执行自定义sql语句

    SELECT * from adinfo WHERE 1481286720 BETWEEN stime AND etime OR (1481297520 BETWEEN stime AND etime)
    model.query(...args)
    
    return {Promise} //指定 SQL 语句执行查询。

    相当于:

    let addCheck = await this.model('adinfo').query('SELECT * from adinfo WHERE ' + stime + ' BETWEEN stime AND etime OR (' + etime + ' BETWEEN stime AND etime)');

    完整版就是这样的:

    let postDatas = this.post();
    let stime = postDatas.stime;
    let etime = postDatas.etime;
    // SELECT * from adinfo WHERE 1481286720 BETWEEN stime AND etime OR (1481297520 BETWEEN stime AND etime)
    // let addCheck = await this.model('adinfo').where({stime:['between', 'stime,etime'],etime:['between', 'stime,etime'],_logic:"OR"}).select();
    let addCheck = await this.model('adinfo').query('SELECT * from adinfo WHERE ' + stime + ' BETWEEN stime AND etime OR (' + etime + ' BETWEEN stime AND etime)');

    原来,thinkjs还是那么的神秘~

  • 相关阅读:
    生成器笔记
    迭代器笔记
    hashilib_module
    Ubuntu操作及各种命令笔记
    python正则表达式2
    python正则表达式1
    python文件操作(with关键字)
    python文件操作
    python包
    python模块
  • 原文地址:https://www.cnblogs.com/zhengyeye/p/6184352.html
Copyright © 2011-2022 走看看