33 */
44
55import { SQLiteCloudRowset } from '../src'
6+ import { RowCallback , RowCountCallback } from '../src/types'
67import { getChinookDatabase } from './shared'
78
8- describe ( 'Statement.prepare' , ( ) => {
9- it ( 'prepare without initial bindings' , done => {
10- const chinook = getChinookDatabase ( )
11- expect ( chinook ) . toBeDefined ( )
12- const statement = chinook . prepare ( 'SELECT * FROM tracks WHERE albumId = ?;' , ( err : Error , results : any ) => {
13- expect ( err ) . toBeNull ( )
9+ it ( 'Database.prepare without initial bindings' , done => {
10+ const chinook = getChinookDatabase ( )
11+ expect ( chinook ) . toBeDefined ( )
12+ const statement = chinook . prepare ( 'SELECT * FROM tracks WHERE albumId = ?;' , ( err : Error , results : any ) => {
13+ expect ( err ) . toBeNull ( )
14+ } )
15+
16+ statement . all ( 3 , ( error , rows ) => {
17+ expect ( error ) . toBeNull ( )
18+ expect ( rows ) . toBeDefined ( )
19+ expect ( rows ) . toHaveLength ( 3 )
20+ expect ( rows ) . toBeInstanceOf ( SQLiteCloudRowset )
21+ expect ( rows ) . toMatchObject ( [
22+ {
23+ AlbumId : 3 ,
24+ Bytes : 3990994 ,
25+ Composer : 'F. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman' ,
26+ GenreId : 1 ,
27+ MediaTypeId : 2 ,
28+ Milliseconds : 230619 ,
29+ Name : 'Fast As a Shark' ,
30+ TrackId : 3 ,
31+ UnitPrice : 0.99
32+ } ,
33+ {
34+ AlbumId : 3 ,
35+ Bytes : 4331779 ,
36+ Composer : 'F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider & W. Hoffman' ,
37+ GenreId : 1 ,
38+ MediaTypeId : 2 ,
39+ Milliseconds : 252051 ,
40+ Name : 'Restless and Wild' ,
41+ TrackId : 4 ,
42+ UnitPrice : 0.99
43+ } ,
44+ {
45+ AlbumId : 3 ,
46+ Bytes : 6290521 ,
47+ Composer : 'Deaffy & R.A. Smith-Diesel' ,
48+ GenreId : 1 ,
49+ MediaTypeId : 2 ,
50+ Milliseconds : 375418 ,
51+ Name : 'Princess of the Dawn' ,
52+ TrackId : 5 ,
53+ UnitPrice : 0.99
54+ }
55+ ] )
56+
57+ chinook . close ( error => {
58+ expect ( error ) . toBeNull ( )
59+ done ( )
1460 } )
61+ } )
62+ } )
63+
64+ it ( 'Statement.all' , done => {
65+ const chinook = getChinookDatabase ( )
66+ expect ( chinook ) . toBeDefined ( )
67+ const statement = chinook . prepare ( 'SELECT * FROM tracks WHERE albumId = ?;' , ( err : Error , results : any ) => {
68+ expect ( err ) . toBeNull ( )
69+ } )
70+
71+ statement . all ( 3 , ( error , rows ) => {
72+ expect ( error ) . toBeNull ( )
73+ expect ( rows ) . toBeDefined ( )
74+ expect ( rows ) . toHaveLength ( 3 )
75+ expect ( rows ) . toBeInstanceOf ( SQLiteCloudRowset )
1576
16- statement . all ( 3 , ( error , rows ) => {
77+ statement . all ( 4 , ( error , rows ) => {
1778 expect ( error ) . toBeNull ( )
1879 expect ( rows ) . toBeDefined ( )
19- expect ( rows ) . toHaveLength ( 3 )
80+ expect ( rows ) . toHaveLength ( 8 )
2081 expect ( rows ) . toBeInstanceOf ( SQLiteCloudRowset )
21- expect ( rows ) . toMatchObject ( [
22- {
23- AlbumId : 3 ,
24- Bytes : 3990994 ,
25- Composer : 'F. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman' ,
26- GenreId : 1 ,
27- MediaTypeId : 2 ,
28- Milliseconds : 230619 ,
29- Name : 'Fast As a Shark' ,
30- TrackId : 3 ,
31- UnitPrice : 0.99
32- } ,
33- {
34- AlbumId : 3 ,
35- Bytes : 4331779 ,
36- Composer : 'F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider & W. Hoffman' ,
37- GenreId : 1 ,
38- MediaTypeId : 2 ,
39- Milliseconds : 252051 ,
40- Name : 'Restless and Wild' ,
41- TrackId : 4 ,
42- UnitPrice : 0.99
43- } ,
44- {
45- AlbumId : 3 ,
46- Bytes : 6290521 ,
47- Composer : 'Deaffy & R.A. Smith-Diesel' ,
48- GenreId : 1 ,
49- MediaTypeId : 2 ,
50- Milliseconds : 375418 ,
51- Name : 'Princess of the Dawn' ,
52- TrackId : 5 ,
53- UnitPrice : 0.99
54- }
55- ] )
5682
5783 chinook . close ( error => {
5884 expect ( error ) . toBeNull ( )
@@ -61,3 +87,68 @@ describe('Statement.prepare', () => {
6187 } )
6288 } )
6389} )
90+
91+ it ( 'Statement.each' , done => {
92+ const chinook = getChinookDatabase ( )
93+ expect ( chinook ) . toBeDefined ( )
94+
95+ let rowCount = 0
96+
97+ const rowCallback = ( error : Error | null , row : any ) => {
98+ rowCount += 1
99+ expect ( error ) . toBeNull ( )
100+ expect ( row ) . toBeDefined ( )
101+ expect ( row ) . toMatchObject ( { } )
102+ }
103+
104+ const completeCallback : RowCountCallback = ( error , numberOfRows ) => {
105+ expect ( error ) . toBeNull ( )
106+ expect ( rowCount ) . toBe ( 8 )
107+ expect ( numberOfRows ) . toBe ( 8 )
108+ chinook . close ( error => {
109+ expect ( error ) . toBeNull ( )
110+ done ( )
111+ } )
112+ }
113+
114+ const statement = chinook . prepare < any > ( 'SELECT * FROM tracks WHERE albumId = ?;' , ( err : Error , results : any ) => {
115+ expect ( err ) . toBeNull ( )
116+ } )
117+
118+ // album 4 has 8 rows
119+ statement . each ( 4 , rowCallback , completeCallback )
120+ } )
121+
122+ it ( 'Statement.get' , done => {
123+ const chinook = getChinookDatabase ( )
124+ expect ( chinook ) . toBeDefined ( )
125+ const statement = chinook . prepare ( 'SELECT * FROM tracks WHERE albumId = ?;' , ( err : Error , results : any ) => {
126+ expect ( err ) . toBeNull ( )
127+ } )
128+
129+ statement . get ( 3 , ( error , row ) => {
130+ expect ( error ) . toBeNull ( )
131+ expect ( row ) . toBeDefined ( )
132+ expect ( Object . keys ( row ) ) . toStrictEqual ( [ 'TrackId' , 'Name' , 'AlbumId' , 'MediaTypeId' , 'GenreId' , 'Composer' , 'Milliseconds' , 'Bytes' , 'UnitPrice' ] )
133+
134+ chinook . close ( error => {
135+ expect ( error ) . toBeNull ( )
136+ done ( )
137+ } )
138+ } )
139+ } )
140+
141+ it ( 'Statement.run' , done => {
142+ const chinook = getChinookDatabase ( )
143+ expect ( chinook ) . toBeDefined ( )
144+ const statement = chinook . prepare ( 'SET CLIENT KEY COMPRESSION TO ?; ' , ( err : Error , results : any ) => {
145+ expect ( err ) . toBeNull ( )
146+ } )
147+
148+ statement . run ( 1 , error => {
149+ expect ( error ) . toBeNull ( )
150+
151+ chinook . close ( )
152+ done ( )
153+ } )
154+ } )
0 commit comments