diff --git a/package-lock.json b/package-lock.json index 106cd84..9ae25c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "react", + "name": "react-sqljs-demo", "version": "1.0.0", "lockfileVersion": 1, "requires": true, @@ -5288,16 +5288,6 @@ "flat-cache": "^2.0.1" } }, - "file-loader": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/file-loader/-/file-loader-5.1.0.tgz", - "integrity": "sha512-u/VkLGskw3Ue59nyOwUwXI/6nuBCo7KBkniB/l7ICwr/7cPNGsL1WCXUp3GB0qgOOKU1TiP49bv4DZF/LJqprg==", - "dev": true, - "requires": { - "loader-utils": "^1.4.0", - "schema-utils": "^2.5.0" - } - }, "file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", @@ -10442,9 +10432,9 @@ } }, "react-app-rewired": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/react-app-rewired/-/react-app-rewired-2.1.5.tgz", - "integrity": "sha512-Gr8KfCeL9/PTQs8Vvxc7v8wQ9vCFMnYPhcAkrMlzkLiMFXS+BgSwm11MoERjZm7dpA2WjTi+Pvbu/w7rujAV+A==", + "version": "2.1.8", + "resolved": "https://registry.npmjs.org/react-app-rewired/-/react-app-rewired-2.1.8.tgz", + "integrity": "sha512-wjXPdKPLscA7mn0I1de1NHrbfWdXz4S1ladaGgHVKdn1hTgKK5N6EdGIJM0KrS6bKnJBj7WuqJroDTsPKKr66Q==", "dev": true, "requires": { "semver": "^5.6.0" diff --git a/package.json b/package.json index 8f8dd87..8df790e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "devDependencies": { "copy-webpack-plugin": "^5.1.1", - "react-app-rewired": "^2.1.5", + "react-app-rewired": "^2.1.8", "typescript": "3.3.3" }, "scripts": { diff --git a/public/test.db b/public/test.db new file mode 100644 index 0000000..3f9c72f Binary files /dev/null and b/public/test.db differ diff --git a/public/z_test.db b/public/z_test.db new file mode 100644 index 0000000..25fb399 Binary files /dev/null and b/public/z_test.db differ diff --git a/src/App.js b/src/App.js index 01f6190..4b3a929 100644 --- a/src/App.js +++ b/src/App.js @@ -14,15 +14,21 @@ export default class App extends React.Component { // sql.js needs to fetch its wasm file, so we cannot immediately instantiate the database // without any configuration, initSqlJs will fetch the wasm files directly from the same path as the js // see ../config-overrides.js - initSqlJs() - .then(SQL => this.setState({ db: new SQL.Database() })) - .catch(err => this.setState({ err })); + const me = this; + Promise.all([initSqlJs(), fetch('./z_test.db')]).then(async res => { + const SQLite = res[0], dbStorage = res[1]; + const db = new SQLite.Database(new Uint8Array(await dbStorage.arrayBuffer())); + + me.setState({db: db}); + }).catch(err => { + me.setState({err}); + }); } exec(sql) { let results = null, err = null; try { - // The sql is executed synchronously on the UI thread. + // The sql is executed synchronously on the UI thread. // You may want to use a web worker results = this.state.db.exec(sql); // an array of objects is returned } catch (e) { @@ -30,6 +36,8 @@ export default class App extends React.Component { err = e } this.setState({ results, err }) + console.log('results') + console.log(results) } /** @@ -70,7 +78,8 @@ export default class App extends React.Component { + defaultValue="SELECT * FROM table1" + />
{(err || "").toString()}
diff --git a/z_test.sql b/z_test.sql new file mode 100644 index 0000000..fda693b --- /dev/null +++ b/z_test.sql @@ -0,0 +1,9 @@ +.open C:/path/to/test.db; + +create table table1( + var1 varchar(10), + var2 smallint); + +insert into table1 values ('A', 1); +insert into table1 values ('B', 2); +