-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added opaque types support over primitives in find-options (#9560)
* added opaque types support over primitives in find-options * removed lock-verify because of its deprecation * fixing auto type mapping
- Loading branch information
Showing
7 changed files
with
146 additions
and
6 deletions.
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
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
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
15 changes: 15 additions & 0 deletions
15
test/functional/find-options/opaque-types-over-primitives/entity/Post.ts
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Column, Entity, PrimaryColumn } from "../../../../../src" | ||
|
||
export type WithType<T> = T & { type: "Post" } | ||
|
||
@Entity() | ||
export class Post { | ||
@PrimaryColumn({ type: Number }) | ||
id: number & { type: "Post" } | ||
|
||
@Column({ type: String }) | ||
title: string & { type: "Post" } | ||
|
||
@Column({ type: Boolean }) | ||
isEdited: boolean & { type: "Post" } | ||
} |
100 changes: 100 additions & 0 deletions
100
...al/find-options/opaque-types-over-primitives/find-options-opaque-types-over-primitives.ts
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import "reflect-metadata" | ||
import "../../../utils/test-setup" | ||
import { DataSource } from "../../../../src" | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../../utils/test-utils" | ||
import { Post, WithType } from "./entity/Post" | ||
|
||
describe("find options > opaque-types-over-primitives", () => { | ||
let dataSources: DataSource[] | ||
before( | ||
async () => | ||
(dataSources = await createTestingConnections({ | ||
__dirname, | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(dataSources)) | ||
after(() => closeTestingConnections(dataSources)) | ||
|
||
async function prepareData(dataSource: DataSource) { | ||
const post1 = new Post() | ||
post1.id = 1 as WithType<number> | ||
post1.title = "Hello" as WithType<string> | ||
post1.isEdited = true as WithType<boolean> | ||
await dataSource.manager.save(post1) | ||
} | ||
|
||
it("should work in select", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
await prepareData(dataSource) | ||
|
||
const posts1 = await dataSource | ||
.createQueryBuilder(Post, "post") | ||
.setFindOptions({ | ||
select: { | ||
id: true, | ||
title: true, | ||
isEdited: true, | ||
}, | ||
}) | ||
.getMany() | ||
|
||
posts1.should.be.eql([ | ||
{ id: 1, title: "Hello", isEdited: true }, | ||
]) | ||
}), | ||
)) | ||
|
||
it("should work in where", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
await prepareData(dataSource) | ||
|
||
const posts = await dataSource | ||
.createQueryBuilder(Post, "post") | ||
.setFindOptions({ | ||
where: { | ||
id: 1 as WithType<number>, | ||
}, | ||
}) | ||
.getMany() | ||
|
||
posts.should.be.eql([ | ||
{ | ||
id: 1, | ||
title: "Hello", | ||
isEdited: true, | ||
}, | ||
]) | ||
}), | ||
)) | ||
|
||
it("should work in order by", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
await prepareData(dataSource) | ||
|
||
const posts1 = await dataSource | ||
.createQueryBuilder(Post, "post") | ||
.setFindOptions({ | ||
order: { | ||
id: "asc", | ||
title: "asc", | ||
isEdited: "asc", | ||
}, | ||
}) | ||
.getMany() | ||
posts1.should.be.eql([ | ||
{ | ||
id: 1, | ||
title: "Hello", | ||
isEdited: true, | ||
}, | ||
]) | ||
}), | ||
)) | ||
}) |