-
-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for WHERE LIKE clauses in SQL drivers via native regexps
- Loading branch information
Showing
6 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,21 @@ EntityManager.transactional(cb: (em: EntityManager) => Promise<any>): Promise<an | |
|
||
Keep in mind transactions are supported only in MySQL driver currently. | ||
|
||
## LIKE queries | ||
|
||
SQL do support LIKE queries via native JS regular expressions: | ||
|
||
```typescript | ||
const author1 = new Author2('Author 1', '[email protected]'); | ||
const author2 = new Author2('Author 2', '[email protected]'); | ||
const author3 = new Author2('Author 3', '[email protected]'); | ||
await orm.em.persist([author1, author2, author3]); | ||
|
||
// finds authors with email like '%exa%le.c_m' | ||
const authors = await orm.em.find(Author2, { email: /exa.*le\.c.m$/ }); | ||
console.log(authors); // all 3 authors found | ||
``` | ||
|
||
## Native collection methods | ||
|
||
Sometimes you need to perform some bulk operation, or you just want to populate your | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,20 @@ describe('EntityManagerMySql', () => { | |
expect(ref.isInitialized()).toBe(true); | ||
}); | ||
|
||
test('findOne supports regexps', async () => { | ||
const author1 = new Author2('Author 1', '[email protected]'); | ||
const author2 = new Author2('Author 2', '[email protected]'); | ||
const author3 = new Author2('Author 3', '[email protected]'); | ||
await orm.em.persist([author1, author2, author3]); | ||
orm.em.clear(); | ||
|
||
const authors = await orm.em.find(Author2, { email: /exa.*le\.c.m$/ }); | ||
expect(authors.length).toBe(3); | ||
expect(authors[0].name).toBe('Author 1'); | ||
expect(authors[1].name).toBe('Author 2'); | ||
expect(authors[2].name).toBe('Author 3'); | ||
}); | ||
|
||
test('stable results of serialization', async () => { | ||
const god = new Author2('God', '[email protected]'); | ||
const bible = new Book2('Bible', god); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,20 @@ describe('EntityManagerSqlite', () => { | |
expect(ref.isInitialized()).toBe(true); | ||
}); | ||
|
||
test('findOne supports regexps', async () => { | ||
const author1 = new Author2('Author 1', '[email protected]'); | ||
const author2 = new Author2('Author 2', '[email protected]'); | ||
const author3 = new Author2('Author 3', '[email protected]'); | ||
await orm.em.persist([author1, author2, author3]); | ||
orm.em.clear(); | ||
|
||
const authors = await orm.em.find(Author2, { email: /exa.*le\.c.m$/ }); | ||
expect(authors.length).toBe(3); | ||
expect(authors[0].name).toBe('Author 1'); | ||
expect(authors[1].name).toBe('Author 2'); | ||
expect(authors[2].name).toBe('Author 3'); | ||
}); | ||
|
||
test('stable results of serialization', async () => { | ||
const god = new Author2('God', '[email protected]'); | ||
const bible = new Book2('Bible', god); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters