|
1 | | -import stream, { TransformCallback } from "stream"; |
2 | | -import { Firebolt } from "../../../src/index"; |
| 1 | +import { Firebolt } from "../../../src"; |
3 | 2 |
|
4 | 3 | const connectionParams = { |
5 | 4 | auth: { |
6 | | - username: process.env.FIREBOLT_USERNAME as string, |
7 | | - password: process.env.FIREBOLT_PASSWORD as string |
| 5 | + client_id: process.env.FIREBOLT_CLIENT_ID as string, |
| 6 | + client_secret: process.env.FIREBOLT_CLIENT_SECRET as string |
8 | 7 | }, |
| 8 | + account: process.env.FIREBOLT_ACCOUNT as string, |
9 | 9 | database: process.env.FIREBOLT_DATABASE as string, |
10 | 10 | engineName: process.env.FIREBOLT_ENGINE_NAME as string |
11 | 11 | }; |
12 | 12 |
|
13 | | -jest.setTimeout(20000); |
| 13 | +jest.setTimeout(250000); |
14 | 14 |
|
15 | 15 | describe("streams", () => { |
16 | | - it("stream transformters", async () => { |
17 | | - class SerializeRowStream extends stream.Transform { |
18 | | - public constructor() { |
19 | | - super({ |
20 | | - objectMode: true, |
21 | | - transform( |
22 | | - row: any, |
23 | | - encoding: BufferEncoding, |
24 | | - callback: TransformCallback |
25 | | - ) { |
26 | | - const transformed = JSON.stringify(row); |
27 | | - this.push(transformed); |
28 | | - this.push("\n"); |
29 | | - callback(); |
30 | | - } |
31 | | - }); |
32 | | - } |
33 | | - } |
34 | | - |
| 16 | + it("stream transformers", async () => { |
35 | 17 | const firebolt = Firebolt({ |
36 | 18 | apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string |
37 | 19 | }); |
38 | 20 |
|
39 | | - const serializedStream = new SerializeRowStream(); |
40 | | - |
41 | 21 | const connection = await firebolt.connect(connectionParams); |
42 | 22 |
|
43 | | - const statement = await connection.execute("select 1 union all select 2"); |
| 23 | + const statement = await connection.executeStream( |
| 24 | + `select 1 from generate_series(1, 250000000)` //~1 GB response |
| 25 | + ); |
44 | 26 |
|
45 | 27 | const { data } = await statement.streamResult(); |
46 | | - |
47 | | - data.pipe(serializedStream).pipe(process.stdout); |
| 28 | + let sum = 0; |
| 29 | + |
| 30 | + data |
| 31 | + .on("meta", meta => { |
| 32 | + console.log("Meta:", meta); |
| 33 | + }) |
| 34 | + .on("data", row => { |
| 35 | + sum += row[0]; |
| 36 | + }); |
48 | 37 |
|
49 | 38 | await new Promise(resolve => { |
50 | 39 | data.on("end", () => { |
| 40 | + expect(sum).toEqual(250000000); |
51 | 41 | resolve(null); |
52 | 42 | }); |
53 | 43 | }); |
|
0 commit comments