Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where 是否可以支持比较? #41

Closed
musicode opened this issue Nov 26, 2017 · 10 comments
Closed

where 是否可以支持比较? #41

musicode opened this issue Nov 26, 2017 · 10 comments

Comments

@musicode
Copy link

源码如下:

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
Copy link
Author

musicode commented Jan 6, 2018

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

@musicode
Copy link
Author

musicode commented Jan 6, 2018

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

@jojo-d
Copy link

jojo-d commented Jan 14, 2018

急切需要这几个运算符

@musicode
Copy link
Author

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

@sanshao
Copy link

sanshao commented Mar 2, 2018

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

@shiny
Copy link

shiny commented May 4, 2018

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

@hghwill
Copy link

hghwill commented Jun 8, 2018

有替代的mysql 库吗?

@LuDongWei
Copy link

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

@kratospan
Copy link

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

@musicode
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants