Skip to content

Commit 1220b7b

Browse files
authored
add fetch instructions to README (#436)
* add fetch instructions to README It took me a little while to figure out, even though it's not simple, so I thought it would be a good addition to the docs * use promise.all instead of sequential awaits per discussion on #436
1 parent 8593ca1 commit 1220b7b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ See : https://sql-js.github.io/sql.js/examples/GUI/gui.js
139139

140140
#### Loading a database from a server
141141

142+
##### using fetch
143+
144+
```javascript
145+
const sqlPromise = initSqlJs({
146+
locateFile: file => `https://path/to/your/dist/folder/dist/${file}`
147+
});
148+
const dataPromise = fetch("/path/to/databse.sqlite").then(res => res.arrayBuffer());
149+
const [SQL, buf] = await Promise.all([sqlPromise, dataPromise])
150+
const db = new SQL.Database(new Uint8Array(buf));
151+
```
152+
153+
##### using XMLHttpRequest
154+
142155
```javascript
143156
var xhr = new XMLHttpRequest();
144157
// For example: https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite

0 commit comments

Comments
 (0)