Skip to content

Commit

Permalink
docs: docs and tests for case insensitive like operator (#6281)
Browse files Browse the repository at this point in the history
* Add doc + tests for case insensitive like operator

* added postgres check since its a postgres-specific

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
  • Loading branch information
Paul Brussee and pleerock committed Sep 3, 2020
1 parent 295b527 commit dcd4301
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
16 changes: 16 additions & 0 deletions docs/find-options.md
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions docs/zh_CN/find-options.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/find-options/operator/ILike.ts
Expand Up @@ -2,7 +2,7 @@ import {FindOperator} from "../FindOperator";

/**
* Find Options Operator.
* Example: { someField: ILike("%some sting%") }
* Example: { someField: ILike("%SOME string%") }
*/
export function ILike<T>(value: T|FindOperator<T>) {
return new FindOperator("ilike", value);
Expand Down
Expand Up @@ -6,6 +6,7 @@ import {
Connection,
Equal,
If,
ILike,
In,
IsNull,
LessThan,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dcd4301

Please sign in to comment.