import { Connection } from 'typeorm';
export class SomeService { constructor(private readonly connection: Connection) {}
async runRawQuery(sql, params) {
return this.connection.query(sql, params)
}
}
and @InjectDataSource() should be used instead
import { DataSource } from 'typeorm';
export class SomeService { // using Dependency Injection (DI)
constructor(@InjectDataSource() private dataSource: DataSource) {}
async runRawQuery(sql, params) {
return this.dataSource.query(sql, params);
}
}
// simplest solution
import { getManager } from 'typeorm';
async function runRawQuery(sql, params) {
return getManager().query(sql, params);
}
No comments:
Post a Comment