ali-rds icon indicating copy to clipboard operation
ali-rds copied to clipboard

where 是否可以支持比较?

Open musicode opened this issue 7 years ago • 8 comments

源码如下:

proto._where = function(where) {
  if (!where) {
    return '';
  }

  const wheres = [];
  const values = [];
  for (const key in where) {
    const value = where[key];
    if (Array.isArray(value)) {
      wheres.push('?? IN (?)');
    } else {
      wheres.push('?? = ?');
    }
    values.push(key);
    values.push(value);
  }
  if (wheres.length > 0) {
    return this.format(' WHERE ' + wheres.join(' AND '), values);
  }
  return '';

};

看起来仅支持 IN=,但是 != 和其他常用比较运算符也很有用啊,为啥不能顺便支持呢?

还是说,官方推荐,其他比较运算符,自己写 SQL 呢?

musicode avatar Nov 26 '17 06:11 musicode

!=, >, >=, <, <= 这几个方便支持下吗

musicode avatar Jan 06 '18 09:01 musicode

有时候查询因为有这几个运算符就要写整句 SQL,实在是让代码可读性差了好多

musicode avatar Jan 06 '18 09:01 musicode

急切需要这几个运算符

jojo-d avatar Jan 14 '18 17:01 jojo-d

这个库是不是没人维护了啊,每次碰到这个问题,都想来这吐槽

musicode avatar Jan 21 '18 07:01 musicode

看到没人维护了 我也遇到问题了

sanshao avatar Mar 02 '18 14:03 sanshao

我也在找这个的支持,看来没有。 egg.js 内使用了这个库。

shiny avatar May 04 '18 06:05 shiny

有替代的mysql 库吗?

hghwill avatar Jun 08 '18 14:06 hghwill

同求 yong egg 的时候 发现这个,如果比较不支持的话,就干脆全部用sql,内置的写法没什么必要了,不然代码里面搞2种写法也麻烦,求解

LuDongWei avatar Jul 04 '18 02:07 LuDongWei

2023年过来考古的,没想到这个问题2017年已经提出来了,但是到现在都没有解决,而且看作者的意思的话,估计是不打算处理了.因为我在egg-mysql那边看到了,直接就是说 用 query 解决的.

kratospan avatar Nov 17 '23 01:11 kratospan

我都放弃 nodejs 了,node 只适合作为胶水层,不建议在这层加重逻辑,操作数据库就更不建议了

musicode avatar Nov 20 '23 04:11 musicode