@@ -68,23 +68,44 @@ describe('SQLiteCloudBunConnection', () => {
6868 expect ( results ) . toBeNull ( )
6969 } )
7070
71- test ( 'should insert metadata' , async done => {
71+ test ( 'should insert metadata without waiting' , async done => {
72+ const database = `pollo_${ Bun . hash ( Math . random ( ) . toString ( ) ) } .sqlite`
7273 const connection = await getConnection ( )
73- connection . sendCommands ( 'UNUSE DATABASE; REMOVE DATABASE pollo.sqlite IF EXISTS; CREATE DATABASE pollo.sqlite ; USE DATABASE pollo.sqlite;' )
74+ connection . sendCommands ( ` CREATE DATABASE ${ database } ; USE DATABASE ${ database } ;` )
7475 connection . sendCommands ( 'CREATE TABLE pollo (id INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT, lastName TEXT);' )
7576 connection . sendCommands ( "INSERT INTO pollo VALUES (1, 'Cluck', 'Norris')" , ( error , results ) => {
7677 expect ( error ) . toBeNull ( )
7778 expect ( Array . isArray ( results ) ) . toBeTrue ( )
7879 expect ( results ) . toHaveLength ( 6 )
7980 expect ( results [ 0 ] ) . toBe ( 10 )
8081
81- connection . sendCommands ( ' UNUSE DATABASE; REMOVE DATABASE pollo.sqlite IF EXISTS; USE DATABASE chinook.sqlite;' , ( ) => {
82+ connection . sendCommands ( ` UNUSE DATABASE; REMOVE DATABASE ${ database } IF EXISTS;` , ( ) => {
8283 done ( error )
8384 connection . close ( )
8485 } )
8586 } )
8687 } )
8788
89+ test ( 'should insert metadata waiting for each statement' , async done => {
90+ const database = `pollo_${ Bun . hash ( Math . random ( ) . toString ( ) ) } .sqlite`
91+ const connection = await getConnection ( )
92+ connection . sendCommands ( `CREATE DATABASE ${ database } ; USE DATABASE ${ database } ;` , ( error , result ) => {
93+ connection . sendCommands ( 'CREATE TABLE pollo (id INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT, lastName TEXT);' , ( error , result ) => {
94+ connection . sendCommands ( "INSERT INTO pollo VALUES (1, 'Cluck', 'Norris')" , ( error , results ) => {
95+ expect ( error ) . toBeNull ( )
96+ expect ( Array . isArray ( results ) ) . toBeTrue ( )
97+ expect ( results ) . toHaveLength ( 6 )
98+ expect ( results [ 0 ] ) . toBe ( 10 )
99+
100+ connection . sendCommands ( `UNUSE DATABASE; REMOVE DATABASE ${ database } IF EXISTS;` , ( ) => {
101+ done ( error )
102+ connection . close ( )
103+ } )
104+ } )
105+ } )
106+ } )
107+ } )
108+
88109 test ( 'should test integer' , async ( ) => {
89110 const results = await testCommands ( 'TEST INTEGER' )
90111 expect ( results ) . toBe ( 123456 )
0 commit comments