diff --git a/docs/find-options.md b/docs/find-options.md index 138a7a6680..8e924d6e4b 100644 --- a/docs/find-options.md +++ b/docs/find-options.md @@ -268,6 +268,22 @@ will execute following query: SELECT * FROM "post" WHERE "title" LIKE '%out #%' ``` +* `ILike` + +```ts +import {ILike} from "typeorm"; + +const loadedPosts = await connection.getRepository(Post).find({ + title: ILike("%out #%") +}); +``` + +will execute following query: + +```sql +SELECT * FROM "post" WHERE "title" ILIKE '%out #%' +``` + * `Between` ```ts diff --git a/docs/zh_CN/find-options.md b/docs/zh_CN/find-options.md index 1b21e6837f..ecf062fd5f 100644 --- a/docs/zh_CN/find-options.md +++ b/docs/zh_CN/find-options.md @@ -261,6 +261,22 @@ const loadedPosts = await connection.getRepository(Post).find({ SELECT * FROM "post" WHERE "title" LIKE '%out #%' ``` +- `ILike` + +```ts +import { ILike } from "typeorm"; + +const loadedPosts = await connection.getRepository(Post).find({ + title: ILike("%out #%") +}); +``` + +将执行以下查询: + +```sql +SELECT * FROM "post" WHERE "title" ILIKE '%out #%' +``` + - `Between` ```ts diff --git a/src/find-options/operator/ILike.ts b/src/find-options/operator/ILike.ts index 301e99ed35..1d3cfaffe4 100644 --- a/src/find-options/operator/ILike.ts +++ b/src/find-options/operator/ILike.ts @@ -2,7 +2,7 @@ import {FindOperator} from "../FindOperator"; /** * Find Options Operator. - * Example: { someField: ILike("%some sting%") } + * Example: { someField: ILike("%SOME string%") } */ export function ILike(value: T|FindOperator) { return new FindOperator("ilike", value); diff --git a/test/functional/repository/find-options-operators/repository-find-operators.ts b/test/functional/repository/find-options-operators/repository-find-operators.ts index b7b1f1e8cc..c437be4a6f 100644 --- a/test/functional/repository/find-options-operators/repository-find-operators.ts +++ b/test/functional/repository/find-options-operators/repository-find-operators.ts @@ -6,6 +6,7 @@ import { Connection, Equal, If, + ILike, In, IsNull, LessThan, @@ -518,6 +519,50 @@ 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"; + post1.likes = 12; + await connection.manager.save(post1); + const post2 = new Post(); + post2.title = "ABOUT #2"; + post2.likes = 3; + await connection.manager.save(post2); + + // check operator + const loadedPosts = await connection.getRepository(Post).find({ + title: ILike("%out #%") + }); + loadedPosts.should.be.eql([{ id: 1, likes: 12, title: "about #1" }, { id: 2, likes: 3, title: "ABOUT #2" }]); + + }))); + + 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"; + post1.likes = 12; + await connection.manager.save(post1); + const post2 = new Post(); + post2.title = "ABOUT #2"; + post2.likes = 3; + await connection.manager.save(post2); + + // check operator + const loadedPosts = await connection.getRepository(Post).find({ + title: Not(ILike("%out #1")) + }); + loadedPosts.should.be.eql([{ id: 2, likes: 3, title: "ABOUT #2" }]); + + }))); + it("between", () => Promise.all(connections.map(async connection => { // insert some fake data