@@ -14,22 +14,30 @@ export default class App extends React.Component {
1414 // sql.js needs to fetch its wasm file, so we cannot immediately instantiate the database
1515 // without any configuration, initSqlJs will fetch the wasm files directly from the same path as the js
1616 // see ../config-overrides.js
17- initSqlJs ( )
18- . then ( SQL => this . setState ( { db : new SQL . Database ( ) } ) )
19- . catch ( err => this . setState ( { err } ) ) ;
17+ const me = this ;
18+ Promise . all ( [ initSqlJs ( ) , fetch ( './z_test.db' ) ] ) . then ( async res => {
19+ const SQLite = res [ 0 ] , dbStorage = res [ 1 ] ;
20+ const db = new SQLite . Database ( new Uint8Array ( await dbStorage . arrayBuffer ( ) ) ) ;
21+
22+ me . setState ( { db : db } ) ;
23+ } ) . catch ( err => {
24+ me . setState ( { err} ) ;
25+ } ) ;
2026 }
2127
2228 exec ( sql ) {
2329 let results = null , err = null ;
2430 try {
25- // The sql is executed synchronously on the UI thread.
31+ // The sql is executed synchronously on the UI thread.
2632 // You may want to use a web worker
2733 results = this . state . db . exec ( sql ) ; // an array of objects is returned
2834 } catch ( e ) {
2935 // exec throws an error when the SQL statement is invalid
3036 err = e
3137 }
3238 this . setState ( { results, err } )
39+ console . log ( 'results' )
40+ console . log ( results )
3341 }
3442
3543 /**
@@ -70,7 +78,8 @@ export default class App extends React.Component {
7078 < textarea
7179 onChange = { e => this . exec ( e . target . value ) }
7280 placeholder = "Enter some SQL. No inspiration ? Try “select sqlite_version()”"
73- > </ textarea >
81+ defaultValue = "SELECT * FROM table1"
82+ />
7483
7584 < pre className = "error" > { ( err || "" ) . toString ( ) } </ pre >
7685
0 commit comments