Skip to content

queryBuilder EXISTS query #2815

@victordidenko

Description

@victordidenko

Issue type:

[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Feature request:

Looks like EXISTS is optimised more, if you need to check only rows existence.
So, instead of

SELECT COUNT(*) FROM mytable WHERE a = "foo" AND b = "bar";

better do

SELECT EXISTS(SELECT * FROM mytable WHERE a = "foo" AND b = "bar");

But now query builder doesn't support such kind of queries, you need to write a raw query.
I think it would be cool to have something like

queryBuilder()
  .select('*')
  .from(MyTable, 'tbl')
  .where('tbl.a = :foo AND tbl.b = :bar', { foo, bar })
  .isExists(); // <-- this row

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions