@@ -14,22 +14,30 @@ export default class App extends React.Component {
14
14
// sql.js needs to fetch its wasm file, so we cannot immediately instantiate the database
15
15
// without any configuration, initSqlJs will fetch the wasm files directly from the same path as the js
16
16
// 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
+ } ) ;
20
26
}
21
27
22
28
exec ( sql ) {
23
29
let results = null , err = null ;
24
30
try {
25
- // The sql is executed synchronously on the UI thread.
31
+ // The sql is executed synchronously on the UI thread.
26
32
// You may want to use a web worker
27
33
results = this . state . db . exec ( sql ) ; // an array of objects is returned
28
34
} catch ( e ) {
29
35
// exec throws an error when the SQL statement is invalid
30
36
err = e
31
37
}
32
38
this . setState ( { results, err } )
39
+ console . log ( 'results' )
40
+ console . log ( results )
33
41
}
34
42
35
43
/**
@@ -70,7 +78,8 @@ export default class App extends React.Component {
70
78
< textarea
71
79
onChange = { e => this . exec ( e . target . value ) }
72
80
placeholder = "Enter some SQL. No inspiration ? Try “select sqlite_version()”"
73
- > </ textarea >
81
+ defaultValue = "SELECT * FROM table1"
82
+ />
74
83
75
84
< pre className = "error" > { ( err || "" ) . toString ( ) } </ pre >
76
85
0 commit comments