Skip to content

Commit 0759340

Browse files
committed
Merge branch 'master' into gh-pages
2 parents 8d172e6 + 5467112 commit 0759340

36 files changed

+496028
-303213
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
node_modules/
22
*~
3+
4+
# LLVM bitcode
5+
c/sqlite3.bc
6+
c/extension-functions.bc
7+
# Intermediary js files
8+
js/api.js
9+
js/sql-noopt-raw.js.map
10+
js/sql-optimized.js
11+
js/worker.js
12+
js/sql-raw.js.map

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
language: node_js
22
node_js:
33
- "0.10"
4+
- "4"
5+
- "5"
6+
- "6"
7+
- "node"
8+
sudo: false

AUTHORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Ophir LOJKINE <[email protected]> (https://github.com/lovasoa)
22
@kripken
33
@hankinsoft
4-
4+
@firien
5+
@dinedal

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT license
2+
===========
3+
4+
Copyright (c) 2017 sql.js authors (see AUTHORS)
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

Makefile

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
# Need $(EMSCRIPTEN), for example run with emmake make
1+
EMCC=emcc
22

3-
EMSCRIPTEN?=/usr/bin
3+
CFLAGS=-O2 -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DISABLE_LFS -DLONGDOUBLE_TYPE=double -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS
44

5-
EMCC=$(EMSCRIPTEN)/emcc
5+
all: js/sql.js debug js/worker.sql.js memory-growth
66

7-
CFLAGS=-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DISABLE_LFS -DLONGDOUBLE_TYPE=double -DSQLITE_INT64_TYPE="long long int" -DSQLITE_THREADSAFE=0
7+
# RESERVED_FUNCTION_POINTERS setting is used for registering custom functions
8+
optimized: EMFLAGS= --memory-init-file 0 -O3 -s INLINING_LIMIT=50 -s RESERVED_FUNCTION_POINTERS=64
9+
optimized: js/sql-optimized.js
810

9-
all: js/sql.js
11+
memory-growth: EMFLAGS= --memory-init-file 0 -O3 -s INLINING_LIMIT=50 -s RESERVED_FUNCTION_POINTERS=64 -s ALLOW_MEMORY_GROWTH=1
12+
memory-growth: js/sql-memory-growth.js
1013

11-
debug: EMFLAGS= -O1 -g -s INLINING_LIMIT=10
14+
debug: EMFLAGS= -O1 -g -s INLINING_LIMIT=10 -s RESERVED_FUNCTION_POINTERS=64
1215
debug: js/sql-debug.js
1316

14-
optimized: EMFLAGS= --closure 1 -O3 -s INLINING_LIMIT=50
15-
optimized: js/sql-optimized.js
16-
1717
js/sql.js: optimized
1818
cp js/sql-optimized.js js/sql.js
1919

2020
js/sql%.js: js/shell-pre.js js/sql%-raw.js js/shell-post.js
2121
cat $^ > $@
2222

23-
js/sql%-raw.js: c/sqlite3.bc js/api.js exported_functions
24-
$(EMCC) $(EMFLAGS) -s EXPORTED_FUNCTIONS=@exported_functions c/sqlite3.bc --post-js js/api.js -o $@
23+
js/sql%-raw.js: c/sqlite3.bc c/extension-functions.bc js/api.js exported_functions
24+
$(EMCC) $(EMFLAGS) -s EXPORTED_FUNCTIONS=@exported_functions -s EXTRA_EXPORTED_RUNTIME_METHODS=@exported_runtime_methods c/extension-functions.bc c/sqlite3.bc --post-js js/api.js -o $@ ;\
2525

2626
js/api.js: coffee/api.coffee coffee/exports.coffee coffee/api-data.coffee
27-
coffee --bare --compile --join $@ --compile $^
27+
cat $^ | coffee --bare --compile --stdio > $@
2828

2929
# Web worker API
3030
worker: js/worker.sql.js
3131
js/worker.js: coffee/worker.coffee
32-
coffee --bare --compile --join $@ --compile $^
32+
cat $^ | coffee --bare --compile --stdio > $@
3333

3434
js/worker.sql.js: js/sql.js js/worker.js
3535
cat $^ > $@
@@ -38,9 +38,13 @@ c/sqlite3.bc: c/sqlite3.c
3838
# Generate llvm bitcode
3939
$(EMCC) $(CFLAGS) c/sqlite3.c -o c/sqlite3.bc
4040

41+
c/extension-functions.bc: c/extension-functions.c
42+
$(EMCC) $(CFLAGS) -s LINKABLE=1 c/extension-functions.c -o c/extension-functions.bc
43+
4144
module.tar.gz: test package.json AUTHORS README.md js/sql.js
4245
tar --create --gzip $^ > $@
4346

4447
clean:
45-
rm -rf js/sql*.js js/api.js js/sql*-raw.js c/sqlite3.bc
48+
rm -rf js/sql.js js/api.js js/sql*-raw.js js/worker.sql.js js/worker.js js/sql-memory-growth.js c/sqlite3.bc c/extension-functions.bc
49+
4650

README.md

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# SQLite compiled to javascript
2-
[![Build Status](https://travis-ci.org/lovasoa/sql.js.svg?branch=master)](http://travis-ci.org/lovasoa/sql.js)
2+
[![Build Status](https://travis-ci.org/kripken/sql.js.svg?branch=master)](http://travis-ci.org/kripken/sql.js)
33

44
For the impatients, try the demo here: http://kripken.github.io/sql.js/GUI/
55

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).
89

910
SQLite is public domain, sql.js is MIT licensed.
1011

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+
1115
## Usage
1216

1317
```javascript
14-
var sql = require('./js/sql-api.js');
18+
var sql = require('sql.js');
1519
// or sql = window.SQL if you are in a browser
1620

1721
// Create a database
@@ -43,6 +47,14 @@ console.log(result); // Will print {a:1, b:'world'}
4347
stmt.bind([0, 'hello']);
4448
while (stmt.step()) console.log(stmt.get()); // Will print [0, 'hello']
4549

50+
// You can also use javascript functions inside your SQL code
51+
// Create the js function you need
52+
function add(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+
4658
// free the memory used by the statement
4759
stmt.free();
4860
// You can not use your statement anymore once it has been freed.
@@ -53,9 +65,9 @@ var binaryArray = db.export();
5365
```
5466

5567
## 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
5769

58-
## Exemples
70+
## Examples
5971
The test files provide up to date example of the use of the api.
6072
### Inside the browser
6173
#### Example **HTML** file:
@@ -70,7 +82,7 @@ The test files provide up to date example of the use of the api.
7082
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);
7183
7284
// 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");
7486
stmt.getAsObject({$start:1, $end:1}); // {col1:1, col2:111}
7587
7688
// Bind new values
@@ -96,7 +108,25 @@ dbFileElm.onchange = function() {
96108
r.readAsArrayBuffer(f);
97109
}
98110
```
99-
See : http://lovasoa.github.io/sql.js/GUI/gui.js
111+
See : http://kripken.github.io/sql.js/GUI/gui.js
112+
113+
#### Loading a database from a server
114+
115+
```javascript
116+
var xhr = new XMLHttpRequest();
117+
xhr.open('GET', '/path/to/database.sqlite', true);
118+
xhr.responseType = 'arraybuffer';
119+
120+
xhr.onload = function(e) {
121+
var uInt8Array = new Uint8Array(this.response);
122+
var db = new SQL.Database(uInt8Array);
123+
var contents = db.exec("SELECT * FROM my_table");
124+
// contents is now [{columns:['col1','col2',...], values:[[first row], [second row], ...]}]
125+
};
126+
xhr.send();
127+
```
128+
See: https://github.com/kripken/sql.js/wiki/Load-a-database-from-the-server
129+
100130

101131
### Use from node.js
102132

@@ -123,7 +153,7 @@ var buffer = new Buffer(data);
123153
fs.writeFileSync("filename.sqlite", buffer);
124154
```
125155

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
127157

128158
### Use as web worker
129159
If you don't want to run CPU-intensive SQL queries in your main application thread,
@@ -156,28 +186,15 @@ worker.postMessage({
156186
</script>
157187
```
158188

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
163190

164191
## 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
179196

180197
## Related
181198

182-
* [In-Browser/Client-Side Demo](http://lovasoa.github.io/sql.js/GUI/)
199+
* [In-Browser/Client-Side Demo](http://kripken.github.io/sql.js/GUI/)
183200

0 commit comments

Comments
 (0)