You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the impatients, try the demo here: http://kripken.github.io/sql.js/GUI/
5
5
6
-
sql.js is a port of SQLite to JavaScript, by compiling the SQLite C code with Emscripten.
7
-
no C bindings or node-gyp compilation here.
6
+
*sql.js* is a port of [SQLite](http://sqlite.org/about.html) to JavaScript, by compiling the SQLite C code with [Emscripten](http://kripken.github.io/emscripten-site/docs/introducing_emscripten/about_emscripten.html). It uses a [virtual database file stored in memory](https://kripken.github.io/emscripten-site/docs/porting/files/file_systems_overview.html), and thus **doesn't persist the changes** made to the database. However, it allows you to **import** any existing sqlite file, and to **export** the created database as a [javascript typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays).
7
+
8
+
There is no C bindings or node-gyp compilation here, sql.js is a simple javascript file, that can be used like any traditional javascript library. If you are building a native application in javascript (using Electron for instance), or are working in node.js, you will likely prefer to use [a native binding of SQLite to javascript](https://www.npmjs.com/package/sqlite3).
8
9
9
10
SQLite is public domain, sql.js is MIT licensed.
10
11
12
+
## Documentation
13
+
A [full documentation](http://kripken.github.io/sql.js/documentation/#http://kripken.github.io/sql.js/documentation/class/Database.html) generated from comments inside the source code, is available.
14
+
11
15
## Usage
12
16
13
17
```javascript
14
-
var sql =require('./js/sql-api.js');
18
+
var sql =require('sql.js');
15
19
// or sql = window.SQL if you are in a browser
16
20
17
21
// Create a database
@@ -43,6 +47,14 @@ console.log(result); // Will print {a:1, b:'world'}
43
47
stmt.bind([0, 'hello']);
44
48
while (stmt.step()) console.log(stmt.get()); // Will print [0, 'hello']
45
49
50
+
// You can also use javascript functions inside your SQL code
51
+
// Create the js function you need
52
+
functionadd(a, b) {return a+b;}
53
+
// Specifies the SQL function's name, the number of it's arguments, and the js function to use
54
+
db.create_function("add_js", add);
55
+
// Run a query in which the function is used
56
+
db.run("INSERT INTO hello VALUES (add_js(7, 3), add_js('Hello ', 'world'));"); // Inserts 10 and 'Hello world'
57
+
46
58
// free the memory used by the statement
47
59
stmt.free();
48
60
// You can not use your statement anymore once it has been freed.
@@ -53,9 +65,9 @@ var binaryArray = db.export();
53
65
```
54
66
55
67
## Demo
56
-
There is an online demo available here : http://lovasoa.github.io/sql.js/GUI
68
+
There is an online demo available here : http://kripken.github.io/sql.js/GUI
57
69
58
-
## Exemples
70
+
## Examples
59
71
The test files provide up to date example of the use of the api.
60
72
### Inside the browser
61
73
#### Example **HTML** file:
@@ -70,7 +82,7 @@ The test files provide up to date example of the use of the api.
70
82
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);
71
83
72
84
// Prepare a statement
73
-
var stmt =db.prepare("SELECT * FROM test WHERE a BETWEEN $start AND $end");
85
+
var stmt =db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
@@ -123,7 +153,7 @@ var buffer = new Buffer(data);
123
153
fs.writeFileSync("filename.sqlite", buffer);
124
154
```
125
155
126
-
See : https://github.com/lovasoa/sql.js/blob/master/test/test_node_file.js
156
+
See : https://github.com/kripken/sql.js/blob/master/test/test_node_file.js
127
157
128
158
### Use as web worker
129
159
If you don't want to run CPU-intensive SQL queries in your main application thread,
@@ -156,28 +186,15 @@ worker.postMessage({
156
186
</script>
157
187
```
158
188
159
-
See : https://github.com/lovasoa/sql.js/blob/master/test/test_worker.js
160
-
161
-
## Documentation
162
-
The API is fully documented here : http://lovasoa.github.io/sql.js/documentation/
189
+
See : https://github.com/kripken/sql.js/blob/master/test/test_worker.js
163
190
164
191
## Downloads
165
-
- You can download `sql.js` here : http://lovasoa.github.io/sql.js/js/sql.js
166
-
- And the Web Worker version: http://lovasoa.github.io/sql.js/js/worker.sql.js
167
-
168
-
## Differences from the original sql.js
169
-
* Support for BLOBs
170
-
* Support for prepared statements
171
-
* Cleaner API
172
-
* More recent version of SQLite (3.8.4)
173
-
* Compiled to asm.js (should be faster, at least on firefox)
174
-
* Changed API. Results now have the form <code>[{'columns':[], values:[]}]</code>
175
-
* Improved GUI of the demo. It now has :
176
-
* syntax highlighting
177
-
* nice HTML tables to display results
178
-
* ability to load and save sqlite database files
192
+
- You can download `sql.js` here : https://raw.githubusercontent.com/kripken/sql.js/master/js/sql.js
193
+
- And the Web Worker version: https://raw.githubusercontent.com/kripken/sql.js/master/js/worker.sql.js
194
+
- You can find a non minified or optimized version for debugging, `sql-debug.js` here : https://raw.githubusercontent.com/kripken/sql.js/master/js/sql-debug.js
195
+
- If you see the message, `Cannot enlarge memory arrays`, try this version, `sql-memory-growth.js` here : https://raw.githubusercontent.com/kripken/sql.js/master/js/sql-memory-growth.js
0 commit comments