1
- const { expect } = require ( 'chai' ) ;
2
- const sinon = require ( 'sinon' ) ;
3
- const config = require ( './utils/config' ) ;
4
- const logger = require ( './utils/logger' ) ( config . logger ) ;
5
- const { DBSQLClient } = require ( '../../lib' ) ;
6
- const ArrowResultHandler = require ( '../../lib/result/ArrowResultHandler' ) . default ;
7
- const ArrowResultConverter = require ( '../../lib/result/ArrowResultConverter' ) . default ;
8
- const ResultSlicer = require ( '../../lib/result/ResultSlicer' ) . default ;
1
+ import { expect } from 'chai' ;
2
+ import sinon from 'sinon' ;
3
+ import { DBSQLClient } from '../../lib' ;
4
+ import { ClientConfig } from '../../lib/contracts/IClientContext' ;
5
+ import IDBSQLSession from '../../lib/contracts/IDBSQLSession' ;
6
+ import ArrowResultHandler from '../../lib/result/ArrowResultHandler' ;
7
+ import ArrowResultConverter from '../../lib/result/ArrowResultConverter' ;
8
+ import ResultSlicer from '../../lib/result/ResultSlicer' ;
9
+
10
+ import config from './utils/config' ;
9
11
10
12
const fixtures = require ( '../fixtures/compatibility' ) ;
11
13
const { expected : expectedColumn } = require ( '../fixtures/compatibility/column' ) ;
12
14
const { expected : expectedArrow } = require ( '../fixtures/compatibility/arrow' ) ;
13
15
const { expected : expectedArrowNativeTypes } = require ( '../fixtures/compatibility/arrow_native_types' ) ;
16
+
14
17
const { fixArrowResult } = fixtures ;
15
18
16
- async function openSession ( customConfig ) {
19
+ async function openSession ( customConfig : Partial < ClientConfig > = { } ) {
17
20
const client = new DBSQLClient ( ) ;
18
21
19
22
const clientConfig = client . getConfig ( ) ;
@@ -29,23 +32,23 @@ async function openSession(customConfig) {
29
32
} ) ;
30
33
31
34
return connection . openSession ( {
32
- initialCatalog : config . database [ 0 ] ,
33
- initialSchema : config . database [ 1 ] ,
35
+ initialCatalog : config . catalog ,
36
+ initialSchema : config . schema ,
34
37
} ) ;
35
38
}
36
39
37
- async function execute ( session , statement ) {
40
+ async function execute ( session : IDBSQLSession , statement : string ) {
38
41
const operation = await session . executeStatement ( statement ) ;
39
42
const result = await operation . fetchAll ( ) ;
40
43
await operation . close ( ) ;
41
44
return result ;
42
45
}
43
46
44
- async function deleteTable ( session , tableName ) {
47
+ async function deleteTable ( session : IDBSQLSession , tableName : string ) {
45
48
await execute ( session , `DROP TABLE IF EXISTS ${ tableName } ` ) ;
46
49
}
47
50
48
- async function initializeTable ( session , tableName ) {
51
+ async function initializeTable ( session : IDBSQLSession , tableName : string ) {
49
52
await deleteTable ( session , tableName ) ;
50
53
51
54
const createTable = fixtures . createTableSql . replace ( / \$ \{ t a b l e _ n a m e \} / g, tableName ) ;
@@ -58,15 +61,15 @@ async function initializeTable(session, tableName) {
58
61
describe ( 'Arrow support' , ( ) => {
59
62
const tableName = `dbsql_nodejs_sdk_e2e_arrow_${ config . tableSuffix } ` ;
60
63
61
- function createTest ( testBody , customConfig ) {
64
+ function createTest (
65
+ testBody : ( session : IDBSQLSession ) => void | Promise < void > ,
66
+ customConfig : Partial < ClientConfig > = { } ,
67
+ ) {
62
68
return async ( ) => {
63
69
const session = await openSession ( customConfig ) ;
64
70
try {
65
71
await initializeTable ( session , tableName ) ;
66
72
await testBody ( session ) ;
67
- } catch ( error ) {
68
- logger ( error ) ;
69
- throw error ;
70
73
} finally {
71
74
await deleteTable ( session , tableName ) ;
72
75
await session . close ( ) ;
@@ -82,6 +85,7 @@ describe('Arrow support', () => {
82
85
const result = await operation . fetchAll ( ) ;
83
86
expect ( result ) . to . deep . equal ( expectedColumn ) ;
84
87
88
+ // @ts -expect-error TS2339: Property getResultHandler does not exist on type IOperation
85
89
const resultHandler = await operation . getResultHandler ( ) ;
86
90
expect ( resultHandler ) . to . be . instanceof ( ResultSlicer ) ;
87
91
expect ( resultHandler . source ) . to . be . not . instanceof ( ArrowResultConverter ) ;
@@ -103,6 +107,7 @@ describe('Arrow support', () => {
103
107
const result = await operation . fetchAll ( ) ;
104
108
expect ( fixArrowResult ( result ) ) . to . deep . equal ( expectedArrow ) ;
105
109
110
+ // @ts -expect-error TS2339: Property getResultHandler does not exist on type IOperation
106
111
const resultHandler = await operation . getResultHandler ( ) ;
107
112
expect ( resultHandler ) . to . be . instanceof ( ResultSlicer ) ;
108
113
expect ( resultHandler . source ) . to . be . instanceof ( ArrowResultConverter ) ;
@@ -126,6 +131,7 @@ describe('Arrow support', () => {
126
131
const result = await operation . fetchAll ( ) ;
127
132
expect ( fixArrowResult ( result ) ) . to . deep . equal ( expectedArrowNativeTypes ) ;
128
133
134
+ // @ts -expect-error TS2339: Property getResultHandler does not exist on type IOperation
129
135
const resultHandler = await operation . getResultHandler ( ) ;
130
136
expect ( resultHandler ) . to . be . instanceof ( ResultSlicer ) ;
131
137
expect ( resultHandler . source ) . to . be . instanceof ( ArrowResultConverter ) ;
@@ -155,16 +161,20 @@ describe('Arrow support', () => {
155
161
` ) ;
156
162
157
163
// We use some internals here to check that server returned response with multiple batches
164
+ // @ts -expect-error TS2339: Property getResultHandler does not exist on type IOperation
158
165
const resultHandler = await operation . getResultHandler ( ) ;
159
166
expect ( resultHandler ) . to . be . instanceof ( ResultSlicer ) ;
160
167
expect ( resultHandler . source ) . to . be . instanceof ( ArrowResultConverter ) ;
161
168
expect ( resultHandler . source . source ) . to . be . instanceof ( ArrowResultHandler ) ;
162
169
170
+ // @ts -expect-error TS2339: Property _data does not exist on type IOperation
163
171
sinon . spy ( operation . _data , 'fetchNext' ) ;
164
172
165
173
const result = await resultHandler . fetchNext ( { limit : rowsCount } ) ;
166
174
175
+ // @ts -expect-error TS2339: Property _data does not exist on type IOperation
167
176
expect ( operation . _data . fetchNext . callCount ) . to . be . eq ( 1 ) ;
177
+ // @ts -expect-error TS2339: Property _data does not exist on type IOperation
168
178
const rawData = await operation . _data . fetchNext . firstCall . returnValue ;
169
179
// We don't know exact count of batches returned, it depends on server's configuration,
170
180
// but with much enough rows there should be more than one result batch
@@ -181,6 +191,7 @@ describe('Arrow support', () => {
181
191
const result = await operation . fetchAll ( ) ;
182
192
expect ( fixArrowResult ( result ) ) . to . deep . equal ( expectedArrow ) ;
183
193
194
+ // @ts -expect-error TS2339: Property getResultHandler does not exist on type IOperation
184
195
const resultHandler = await operation . getResultHandler ( ) ;
185
196
expect ( resultHandler ) . to . be . instanceof ( ResultSlicer ) ;
186
197
expect ( resultHandler . source ) . to . be . instanceof ( ArrowResultConverter ) ;
0 commit comments