Skip to content

Commit 3fdb218

Browse files
committed
Example of how to load a database from a server
Fixes sql-js#82
1 parent ede21d1 commit 3fdb218

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ dbFileElm.onchange = function() {
9898
```
9999
See : http://kripken.github.io/sql.js/GUI/gui.js
100100

101+
#### Loading a database from a server
102+
103+
```javascript
104+
var xhr = new XMLHttpRequest();
105+
xhr.open('GET', '/path/to/database.sqlite', true);
106+
xhr.responseType = 'arraybuffer';
107+
108+
xhr.onload = function(e) {
109+
var uInt8Array = new Uint8Array(this.response);
110+
var db = new SQL.Database(uInt8Array);
111+
var contents = db.exec("SELECT * FROM my_table");
112+
// contents is now [{columns:['col1','col2',...], values:[[first row], [second row], ...]}]
113+
};
114+
xhr.send();
115+
```
116+
See: https://github.com/kripken/sql.js/wiki/Load-a-database-from-the-server
117+
118+
101119
### Use from node.js
102120

103121
`sql.js` is [hosted on npm](https://www.npmjs.org/package/sql.js). To install it, you can simply run `npm install sql.js`.

0 commit comments

Comments
 (0)