Skip to content

Commit

Permalink
refactor: query methods should accept generic for return type (#9957)
Browse files Browse the repository at this point in the history
* query should accept generics

* Update DataSource.ts
  • Loading branch information
Newbie012 authored Apr 18, 2023
1 parent 0e56f0f commit f5b93c1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/data-source/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,11 @@ export class DataSource {
/**
* Executes raw SQL query and returns raw database results.
*/
async query(
async query<T = any>(
query: string,
parameters?: any[],
queryRunner?: QueryRunner,
): Promise<any> {
): Promise<T> {
if (InstanceChecker.isMongoEntityManager(this.manager))
throw new TypeORMError(`Queries aren't supported by MongoDB.`)

Expand Down
2 changes: 1 addition & 1 deletion src/entity-manager/EntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class EntityManager {
/**
* Executes raw SQL query and returns raw database results.
*/
async query(query: string, parameters?: any[]): Promise<any> {
async query<T = any>(query: string, parameters?: any[]): Promise<T> {
return this.connection.query(query, parameters, this.queryRunner)
}

Expand Down

0 comments on commit f5b93c1

Please sign in to comment.