@@ -23,7 +23,12 @@ let db: QuickSQLiteConnection = global.db;
23
23
const NUM_READ_CONNECTIONS = 3 ;
24
24
25
25
function generateUserInfo ( ) {
26
- return { id : chance . integer ( ) , name : chance . name ( ) , age : chance . integer ( ) , networth : chance . floating ( ) } ;
26
+ return {
27
+ id : chance . integer ( ) ,
28
+ name : chance . name ( ) ,
29
+ age : chance . integer ( ) ,
30
+ networth : chance . floating ( )
31
+ } ;
27
32
}
28
33
29
34
function createTestUser ( context : { execute : ( sql : string , args ?: any [ ] ) => Promise < QueryResult > } = db ) {
@@ -59,7 +64,9 @@ export function registerBaseTests() {
59
64
db . delete ( ) ;
60
65
}
61
66
62
- global . db = db = open ( 'test' , { numReadConnections : NUM_READ_CONNECTIONS } ) ;
67
+ global . db = db = open ( 'test' , {
68
+ numReadConnections : NUM_READ_CONNECTIONS
69
+ } ) ;
63
70
64
71
await db . execute ( 'DROP TABLE IF EXISTS User; ' ) ;
65
72
await db . execute ( 'CREATE TABLE User ( id INT PRIMARY KEY, name TEXT NOT NULL, age INT, networth REAL) STRICT;' ) ;
@@ -480,7 +487,9 @@ export function registerBaseTests() {
480
487
} ) ;
481
488
482
489
it ( 'Should open a db without concurrency' , async ( ) => {
483
- const singleConnection = open ( 'single_connection' , { numReadConnections : 0 } ) ;
490
+ const singleConnection = open ( 'single_connection' , {
491
+ numReadConnections : 0
492
+ } ) ;
484
493
485
494
const [ p1 , p2 ] = [
486
495
singleConnection . writeLock ( async ( ) => {
@@ -570,9 +579,9 @@ export function registerBaseTests() {
570
579
await db . writeLock ( async ( tx ) => {
571
580
await tx . execute ( 'BEGIN' ) ;
572
581
// Creates 100,000 Users
573
- for ( let i = 0 ; i < numberOfUsers ; i ++ ) {
574
- await tx . execute ( 'INSERT INTO User (id, name, age, networth) VALUES(?, ?, ?, ?)' , [ i , 'steven' , i , 0 ] )
575
- }
582
+ for ( let i = 0 ; i < numberOfUsers ; i ++ ) {
583
+ await tx . execute ( 'INSERT INTO User (id, name, age, networth) VALUES(?, ?, ?, ?)' , [ i , 'steven' , i , 0 ] ) ;
584
+ }
576
585
await tx . execute ( 'COMMIT' ) ;
577
586
} ) ;
578
587
@@ -582,7 +591,9 @@ export function registerBaseTests() {
582
591
} ) ;
583
592
584
593
it ( 'Should attach DBs' , async ( ) => {
585
- const singleConnection = open ( 'single_connection' , { numReadConnections : 0 } ) ;
594
+ const singleConnection = open ( 'single_connection' , {
595
+ numReadConnections : 0
596
+ } ) ;
586
597
await singleConnection . execute ( 'DROP TABLE IF EXISTS Places; ' ) ;
587
598
await singleConnection . execute ( 'CREATE TABLE Places ( id INT PRIMARY KEY, name TEXT NOT NULL) STRICT;' ) ;
588
599
await singleConnection . execute ( 'INSERT INTO "Places" (id, name) VALUES(0, "Beverly Hills")' ) ;
@@ -602,16 +613,12 @@ export function registerBaseTests() {
602
613
let start = performance . now ( ) ;
603
614
for ( let i = 0 ; i < 1000 ; ++ i ) {
604
615
const n = randomIntFromInterval ( 0 , 100000 ) ;
605
- await db . execute ( `INSERT INTO t1(a, b, c) VALUES(?, ?, ?)` , [
606
- i + 1 ,
607
- n ,
608
- numberName ( n ) ,
609
- ] ) ;
616
+ await db . execute ( `INSERT INTO t1(a, b, c) VALUES(?, ?, ?)` , [ i + 1 , n , numberName ( n ) ] ) ;
610
617
}
611
618
await db . execute ( 'PRAGMA wal_checkpoint(RESTART)' ) ;
612
619
let end = performance . now ( ) ;
613
620
let duration = end - start ;
614
-
621
+
615
622
expect ( duration ) . lessThan ( 2000 ) ;
616
623
} ) ;
617
624
} ) ;
0 commit comments