Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/test.db
Binary file not shown.
17 changes: 13 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -70,7 +78,8 @@ export default class App extends React.Component {
<textarea
onChange={e => this.exec(e.target.value)}
placeholder="Enter some SQL. No inpiration ? Try “select sqlite_version()”"
></textarea>
defaultValue="SELECT * FROM db_articles"
/>

<pre className="error">{(err || "").toString()}</pre>

Expand Down