@@ -110,6 +110,111 @@ class MainApp {
110
110
this . log ( type , `end time: ${ endTime } , use ${ ( ( endTime - startTime ) / 1000 ) . toFixed ( 2 ) } s` ) ;
111
111
}
112
112
113
+ async runIndexedDBLoveField ( type ) {
114
+ await window . indexedDBHelper . deleteAllIndexedDB ( ) ;
115
+
116
+ const schemaBuilder = lf . schema . create ( 'todo' , 1 ) ;
117
+ schemaBuilder . createTable ( 'Item' )
118
+ . addColumn ( 'id' , lf . Type . INTEGER )
119
+ . addColumn ( 'description' , lf . Type . STRING )
120
+ . addPrimaryKey ( [ 'id' ] ) ;
121
+
122
+ const db = await schemaBuilder . connect ( ) ;
123
+ db . getSchema ( ) . table ( 'Item' ) ;
124
+
125
+ const { count } = this . runnerConfig ;
126
+ const startTime = Date . now ( ) ;
127
+ this . log ( type , `start time: ${ startTime } , count: ${ count } ` ) ;
128
+ for ( let i = 0 ; i < count ; i ++ ) {
129
+ const item = db . getSchema ( ) . table ( 'Item' ) ;
130
+ const row = item . createRow ( {
131
+ id : i ,
132
+ description : new Array ( 100 ) . fill ( '测试' ) . join ( '' ) ,
133
+ } ) ;
134
+
135
+ await db . insertOrReplace ( ) . into ( item ) . values ( [ row ] ) . exec ( ) ;
136
+
137
+ console . log ( 'Data added successfully' ) ;
138
+ }
139
+ const endTime = Date . now ( ) ;
140
+ this . log ( type , `end time: ${ endTime } , use ${ ( ( endTime - startTime ) / 1000 ) . toFixed ( 2 ) } s` ) ;
141
+ }
142
+
143
+ async runSQLiteWASM ( type ) {
144
+ const SQL = await initSqlJs ( {
145
+ // Required to load the wasm binary asynchronously. Of course, you can host it wherever you want
146
+ // You can omit locateFile completely when running in node
147
+ locateFile : ( ) => '../../../node_modules/sql.js/dist/sql-wasm.wasm' ,
148
+ } ) ;
149
+
150
+ const db = new SQL . Database ( ) ;
151
+ db . run ( 'DROP TABLE IF EXISTS todo' ) ;
152
+ db . run ( 'CREATE TABLE todo (id int, description varchar);' ) ;
153
+
154
+ const { count } = this . runnerConfig ;
155
+ const startTime = Date . now ( ) ;
156
+ this . log ( type , `start time: ${ startTime } , count: ${ count } ` ) ;
157
+ for ( let i = 0 ; i < count ; i ++ ) {
158
+ db . run ( 'INSERT INTO todo VALUES (?,?)' , [ i , new Array ( 100 ) . fill ( '测试' ) . join ( '' ) ] ) ;
159
+ console . log ( 'Data added successfully' ) ;
160
+ }
161
+ const endTime = Date . now ( ) ;
162
+ this . log ( type , `end time: ${ endTime } , use ${ ( ( endTime - startTime ) / 1000 ) . toFixed ( 2 ) } s` ) ;
163
+ }
164
+
165
+ async runSQLiteWASMInWorker ( type ) {
166
+ const worker = new Worker ( '../../../node_modules/sql.js/dist/worker.sql-wasm.js' ) ;
167
+
168
+ worker . onmessage = ( ) => {
169
+ console . log ( 'Database opened' ) ;
170
+ worker . onmessage = event => {
171
+ console . log ( 'Data added successfully' ) ;
172
+ if ( event . data ?. id === 'end' ) {
173
+ const endTime = Date . now ( ) ;
174
+ this . log ( type , `end time: ${ endTime } , use ${ ( ( endTime - startTime ) / 1000 ) . toFixed ( 2 ) } s` ) ;
175
+ }
176
+ } ;
177
+
178
+ worker . postMessage ( {
179
+ id : 'drop' ,
180
+ action : 'exec' ,
181
+ sql : 'DROP TABLE IF EXISTS todo_worker' ,
182
+ } ) ;
183
+
184
+ // create table
185
+ worker . postMessage ( {
186
+ id : 'init' ,
187
+ action : 'exec' ,
188
+ sql : 'CREATE TABLE todo_worker (id int, description varchar);' ,
189
+ } ) ;
190
+
191
+ const { count } = this . runnerConfig ;
192
+ const startTime = Date . now ( ) ;
193
+ this . log ( type , `start time: ${ startTime } , count: ${ count } ` ) ;
194
+ for ( let i = 0 ; i < count ; i ++ ) {
195
+ worker . postMessage ( {
196
+ id : i ,
197
+ action : 'exec' ,
198
+ sql : 'INSERT INTO todo_worker VALUES ($id, $description)' ,
199
+ params : { $id : i , $description : new Array ( 100 ) . fill ( '测试' ) . join ( '' ) } ,
200
+ } ) ;
201
+ }
202
+
203
+ // 以 count 结束
204
+ worker . postMessage ( {
205
+ id : 'end' ,
206
+ action : 'exec' ,
207
+ sql : 'select count(*) from todo_worker' ,
208
+ } ) ;
209
+ } ;
210
+
211
+ worker . onerror = e => console . log ( 'Worker error: ' , e ) ;
212
+ worker . postMessage ( {
213
+ id : 'open' ,
214
+ action : 'open' ,
215
+ } ) ;
216
+ }
217
+
113
218
async runSQLiteElectronNative ( type ) {
114
219
const { count } = this . runnerConfig ;
115
220
const startTime = Date . now ( ) ;
0 commit comments