From c9ca6d0d179948bf98878046fa809d6cd517c8dd Mon Sep 17 00:00:00 2001 From: Andriy Oblivantsev Date: Sun, 14 Jun 2020 21:31:11 +0200 Subject: [PATCH] Load test.db sqlite database demo file --- public/test.db | Bin 0 -> 12288 bytes src/App.js | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 public/test.db diff --git a/public/test.db b/public/test.db new file mode 100644 index 0000000000000000000000000000000000000000..3f9c72f07f70fe58c8f4830c3f94691847908c7b GIT binary patch literal 12288 zcmeI#F-yZh6bJBkIXz9GoZ!&)NS78w5D`bMa)e+lHl|>wklF}=w8bVRUHxc&48MV6 zC+XneMJZ(Jtnz>G?!9++5c1pZzTZvqSUt_=lPFiGbU=*JrBXyBOmdT(*fC9+n_!z} zOBHl{@m7~>vZPDWm9Jaw;s^o|fB*y_009U<00Izz00bcL+Xa?vuhDF>m-9RtrSW(a zM)N#*OyjK5TGzhr1X=~1tFBf~<-}2~n(ZWG$M$-GcD1htJ+D8|M`m{#O=8Cm^h02# zJKwwQ_(OH0hpqB{yVgFlM8j(`N~Ys@nLVfGH6KQceD*zum5+ocm7#ps@0X}`lU%-& zT+5Xy2nav`0uX=z1Rwwb2tWV=5P$##{;+`HoDPek5SFP~mI?M#Yv!N0T#@{gAEqE6 j009U<00Izz00bZa0SG_<0ucBI0=t|s&db%ZIJfOD-)u~! literal 0 HcmV?d00001 diff --git a/src/App.js b/src/App.js index eb52283..c58ba7e 100644 --- a/src/App.js +++ b/src/App.js @@ -14,9 +14,17 @@ 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('./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) { @@ -70,7 +78,8 @@ export default class App extends React.Component { + defaultValue="SELECT * FROM db_articles" + />
{(err || "").toString()}