Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: actually return a working ReadStream from SQL Server query runner (
#7893) the sql server query runner wasn't actually returning a ReadStream as expected and there were no tests that confirmed the stream functionality. this corrects both of those problems
- Loading branch information
1 parent
1f64da2
commit e80985f
Showing
2 changed files
with
78 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../src"; | ||
import { expect } from "chai"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Book } from "./entity/Book"; | ||
|
||
describe("query runner > stream", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
entities: [Book], | ||
enabledDrivers: [ "mysql", "cockroachdb", "postgres", "mssql" ], | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should stream data", () => Promise.all(connections.map(async connection => { | ||
await connection.manager.save(Book, { ean: 'a' }); | ||
await connection.manager.save(Book, { ean: 'b' }); | ||
await connection.manager.save(Book, { ean: 'c' }); | ||
await connection.manager.save(Book, { ean: 'd' }); | ||
|
||
const queryRunner = connection.createQueryRunner(); | ||
|
||
const readStream = await queryRunner.stream('SELECT * FROM book'); | ||
|
||
await new Promise((ok) => readStream.on('readable', ok)); | ||
|
||
expect(readStream.read()).to.be.eql({ ean: 'a' }); | ||
expect(readStream.read()).to.be.eql({ ean: 'b' }); | ||
expect(readStream.read()).to.be.eql({ ean: 'c' }); | ||
expect(readStream.read()).to.be.eql({ ean: 'd' }); | ||
expect(readStream.read()).to.be.null; | ||
|
||
await queryRunner.release(); | ||
}))); | ||
|
||
}); |