Skip to content

Commit

Permalink
fix: ILike operator generally available for any driver (#6945)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardofalk committed Oct 21, 2020
1 parent 06903d1 commit 37f0d8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/query-builder/QueryBuilder.ts
Expand Up @@ -15,6 +15,8 @@ import {QueryDeepPartialEntity} from "./QueryPartialEntity";
import {EntityMetadata} from "../metadata/EntityMetadata";
import {ColumnMetadata} from "../metadata/ColumnMetadata";
import {SqljsDriver} from "../driver/sqljs/SqljsDriver";
import {PostgresDriver} from "../driver/postgres/PostgresDriver";
import {CockroachDriver} from "../driver/cockroachdb/CockroachDriver";
import {SqlServerDriver} from "../driver/sqlserver/SqlServerDriver";
import {OracleDriver} from "../driver/oracle/OracleDriver";
import {EntitySchema} from "../";
Expand Down Expand Up @@ -914,6 +916,8 @@ export abstract class QueryBuilder<Entity> {
* Gets SQL needs to be inserted into final query.
*/
protected computeFindOperatorExpression(operator: FindOperator<any>, aliasPath: string, parameters: any[]): string {
const { driver } = this.connection;

switch (operator.type) {
case "not":
if (operator.child) {
Expand All @@ -932,7 +936,11 @@ export abstract class QueryBuilder<Entity> {
case "equal":
return `${aliasPath} = ${parameters[0]}`;
case "ilike":
return `${aliasPath} ILIKE ${parameters[0]}`;
if (driver instanceof PostgresDriver || driver instanceof CockroachDriver) {
return `${aliasPath} ILIKE ${parameters[0]}`;
}

return `UPPER(${aliasPath}) LIKE UPPER(${parameters[0]})`;
case "like":
return `${aliasPath} LIKE ${parameters[0]}`;
case "between":
Expand Down
Expand Up @@ -273,9 +273,6 @@ describe("repository > find options > operators", () => {
})));

it("ilike", () => Promise.all(connections.map(async connection => {
if (!(connection.driver instanceof PostgresDriver))
return;

// insert some fake data
const post1 = new Post();
post1.title = "about #1";
Expand All @@ -295,9 +292,6 @@ describe("repository > find options > operators", () => {
})));

it("not(ilike)", () => Promise.all(connections.map(async connection => {
if (!(connection.driver instanceof PostgresDriver))
return;

// insert some fake data
const post1 = new Post();
post1.title = "about #1";
Expand Down

0 comments on commit 37f0d8f

Please sign in to comment.