8
8
import { FileData , Table , TableWiseFiles } from '../types' ;
9
9
import { DBM } from './dbm' ;
10
10
import { InstanceManagerType } from './instance-manager' ;
11
- import { DBMConstructorOptions } from './types' ;
11
+ import { DBMConstructorOptions , TableConfig } from './types' ;
12
12
13
13
export class MockFileManager implements FileManagerType {
14
14
private fileBufferStore : Record < string , FileBufferStore > = { } ;
@@ -53,7 +53,8 @@ export class MockFileManager implements FileManagerType {
53
53
return fileBuffer . buffer ;
54
54
}
55
55
56
- async mountFileBufferByTableNames ( tableNames : string [ ] ) : Promise < void > {
56
+ async mountFileBufferByTables ( tables : TableConfig [ ] ) : Promise < void > {
57
+ const tableNames = tables . map ( ( table ) => table . name ) ;
57
58
for ( const tableName of tableNames ) {
58
59
for ( const key in this . fileBufferStore ) {
59
60
if ( this . fileBufferStore [ key ] . tableName === tableName ) {
@@ -64,17 +65,6 @@ export class MockFileManager implements FileManagerType {
64
65
}
65
66
}
66
67
67
- async unmountFileBufferByTableNames ( tableNames : string [ ] ) : Promise < void > {
68
- for ( const tableName of tableNames ) {
69
- for ( const key in this . fileBufferStore ) {
70
- if ( this . fileBufferStore [ key ] . tableName === tableName ) {
71
- // unmount operation here
72
- console . log ( `Unmounted file buffer for ${ key } ` ) ;
73
- }
74
- }
75
- }
76
- }
77
-
78
68
async getFilesByTableName ( tableName : string ) : Promise < FileData [ ] > {
79
69
const files : FileData [ ] = [ ] ;
80
70
@@ -96,15 +86,17 @@ export class MockFileManager implements FileManagerType {
96
86
}
97
87
}
98
88
99
- async getFilesNameForTables ( tableNames : string [ ] ) : Promise < TableWiseFiles [ ] > {
89
+ async getFilesNameForTables (
90
+ tableNames : TableConfig [ ]
91
+ ) : Promise < TableWiseFiles [ ] > {
100
92
const data : TableWiseFiles [ ] = [ ] ;
101
93
102
- for ( const tableName of tableNames ) {
103
- const files : string [ ] = [ ] ;
94
+ for ( const { name : tableName } of tableNames ) {
95
+ const files : FileData [ ] = [ ] ;
104
96
105
97
for ( const key in this . fileBufferStore ) {
106
98
if ( this . fileBufferStore [ key ] . tableName === tableName ) {
107
- files . push ( key ) ;
99
+ files . push ( { fileName : key } ) ;
108
100
}
109
101
}
110
102
@@ -170,6 +162,8 @@ describe('DBM', () => {
170
162
let dbm : DBM ;
171
163
let instanceManager : InstanceManager ;
172
164
165
+ const tables = [ { name : 'table1' } ] ;
166
+
173
167
beforeAll ( async ( ) => {
174
168
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
175
169
//@ts -ignore
@@ -201,7 +195,7 @@ describe('DBM', () => {
201
195
} ) ;
202
196
} ) ;
203
197
204
- describe ( 'queryWithTableNames ' , ( ) => {
198
+ describe ( 'queryWithTables ' , ( ) => {
205
199
it ( 'should call the preQuery hook' , async ( ) => {
206
200
const preQuery = jest . fn ( ) ;
207
201
@@ -211,9 +205,9 @@ describe('DBM', () => {
211
205
buffer : new Uint8Array ( ) ,
212
206
} ) ;
213
207
214
- const result = await dbm . queryWithTableNames ( {
208
+ const result = await dbm . queryWithTables ( {
215
209
query : 'SELECT * FROM table1' ,
216
- tableNames : [ 'table1' ] ,
210
+ tables : tables ,
217
211
options : {
218
212
preQuery,
219
213
} ,
@@ -224,27 +218,27 @@ describe('DBM', () => {
224
218
expect ( preQuery ) . toBeCalledWith ( [
225
219
{
226
220
tableName : 'table1' ,
227
- files : [ 'file1' ] ,
221
+ files : [ { fileName : 'file1' } ] ,
228
222
} ,
229
223
] ) ;
230
224
} ) ;
231
225
232
226
it ( 'should execute a query with table names' , async ( ) => {
233
- const result = await dbm . queryWithTableNames ( {
227
+ const result = await dbm . queryWithTables ( {
234
228
query : 'SELECT * FROM table1' ,
235
- tableNames : [ 'table1' ] ,
229
+ tables : tables ,
236
230
} ) ;
237
231
expect ( result ) . toEqual ( [ 'SELECT * FROM table1' ] ) ;
238
232
} ) ;
239
233
240
234
it ( 'should execute multiple queries with table names' , async ( ) => {
241
- const promise1 = dbm . queryWithTableNames ( {
235
+ const promise1 = dbm . queryWithTables ( {
242
236
query : 'SELECT * FROM table1' ,
243
- tableNames : [ 'table1' ] ,
237
+ tables : tables ,
244
238
} ) ;
245
- const promise2 = dbm . queryWithTableNames ( {
239
+ const promise2 = dbm . queryWithTables ( {
246
240
query : 'SELECT * FROM table2' ,
247
- tableNames : [ 'table1' ] ,
241
+ tables : tables ,
248
242
} ) ;
249
243
/**
250
244
* Number of queries in the queue should be 1 as the first query is running
@@ -271,9 +265,9 @@ describe('DBM', () => {
271
265
/**
272
266
* Execute another query
273
267
*/
274
- const promise3 = dbm . queryWithTableNames ( {
268
+ const promise3 = dbm . queryWithTables ( {
275
269
query : 'SELECT * FROM table3' ,
276
- tableNames : [ 'table1' ] ,
270
+ tables : tables ,
277
271
} ) ;
278
272
279
273
/**
@@ -314,17 +308,17 @@ describe('DBM', () => {
314
308
/**
315
309
* Execute a query
316
310
*/
317
- const promise1 = dbm . queryWithTableNames ( {
311
+ const promise1 = dbm . queryWithTables ( {
318
312
query : 'SELECT * FROM table1' ,
319
- tableNames : [ 'table1' ] ,
313
+ tables : tables ,
320
314
} ) ;
321
315
322
316
/**
323
317
* Execute another query
324
318
*/
325
- const promise2 = dbm . queryWithTableNames ( {
319
+ const promise2 = dbm . queryWithTables ( {
326
320
query : 'SELECT * FROM table2' ,
327
- tableNames : [ 'table1' ] ,
321
+ tables : tables ,
328
322
} ) ;
329
323
330
324
/**
@@ -375,17 +369,17 @@ describe('DBM', () => {
375
369
/**
376
370
* Execute a query
377
371
*/
378
- const promise1 = dbm . queryWithTableNames ( {
372
+ const promise1 = dbm . queryWithTables ( {
379
373
query : 'SELECT * FROM table1' ,
380
- tableNames : [ 'table1' ] ,
374
+ tables : tables ,
381
375
} ) ;
382
376
383
377
/**
384
378
* Execute another query
385
379
*/
386
- const promise2 = dbm . queryWithTableNames ( {
380
+ const promise2 = dbm . queryWithTables ( {
387
381
query : 'SELECT * FROM table2' ,
388
- tableNames : [ 'table1' ] ,
382
+ tables : tables ,
389
383
} ) ;
390
384
391
385
/**
@@ -420,9 +414,9 @@ describe('DBM', () => {
420
414
/**
421
415
* Execute a query
422
416
*/
423
- await dbm . queryWithTableNames ( {
417
+ await dbm . queryWithTables ( {
424
418
query : 'SELECT * FROM table1' ,
425
- tableNames : [ 'table1' ] ,
419
+ tables : tables ,
426
420
} ) ;
427
421
428
422
/**
@@ -443,9 +437,9 @@ describe('DBM', () => {
443
437
444
438
// check the current query throws error abort is emitted
445
439
try {
446
- const promise = dbm . queryWithTableNames ( {
440
+ const promise = dbm . queryWithTables ( {
447
441
query : 'SELECT * FROM table1' ,
448
- tableNames : [ 'table1' ] ,
442
+ tables : tables ,
449
443
options : {
450
444
signal : abortController1 . signal ,
451
445
} ,
@@ -467,17 +461,17 @@ describe('DBM', () => {
467
461
468
462
const mockDBMQuery = jest . spyOn ( dbm , 'query' ) ;
469
463
470
- const promise1 = dbm . queryWithTableNames ( {
464
+ const promise1 = dbm . queryWithTables ( {
471
465
query : 'SELECT * FROM table1' ,
472
- tableNames : [ 'table1' ] ,
466
+ tables : tables ,
473
467
options : {
474
468
signal : abortController1 . signal ,
475
469
} ,
476
470
} ) ;
477
471
478
- const promise2 = dbm . queryWithTableNames ( {
472
+ const promise2 = dbm . queryWithTables ( {
479
473
query : 'SELECT * FROM table2' ,
480
- tableNames : [ 'table2' ] ,
474
+ tables : [ { name : 'table2' } ] ,
481
475
options : {
482
476
signal : abortController2 . signal ,
483
477
} ,
0 commit comments