Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/kripken/sql.js into custo…
Browse files Browse the repository at this point in the history
…m-functions
  • Loading branch information
Christopher J. Brody committed Jan 9, 2020
2 parents 3eb8f81 + e810a2c commit 86865e6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The test files provide up to date example of the use of the api.
<script src='/dist/sql-wasm.js'></script>
<script>
config = {
locateFile: filename => `/dist/${filename}`
locateFile: filename => `/dist/${filename}`
}
// The `initSqlJs` function is globally provided by all of the main dist files if loaded in the browser.
// We must specify this locateFile function if we are loading a wasm file from anywhere other than the current html page's folder.
Expand All @@ -97,11 +97,11 @@ The test files provide up to date example of the use of the api.
db.run("CREATE TABLE test (col1, col2);");
// Insert two rows: (1,111) and (2,222)
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);
// Prepare a statement
var stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
stmt.getAsObject({$start:1, $end:1}); // {col1:1, col2:111}
// Bind new values
stmt.bind({$start:1, $end:2});
while(stmt.step()) { //
Expand Down Expand Up @@ -161,7 +161,7 @@ Alternatively, you can simply download `sql-wasm.js` and `sql-wasm.wasm`, from t
var fs = require('fs');
var initSqlJs = require('sql-wasm.js');
var filebuffer = fs.readFileSync('test.sqlite');

initSqlJs().then(function(SQL){
// Load the db
var db = new SQL.Database(filebuffer);
Expand Down Expand Up @@ -196,7 +196,7 @@ Example:
worker.onmessage = event => {
console.log(event.data); // The result of the query
};
worker.postMessage({
id: 2,
action: 'exec',
Expand All @@ -221,7 +221,7 @@ This library includes both WebAssembly and asm.js versions of Sqlite. (WebAssemb

## Upgrading from 0.x to 1.x

Version 1.0 of sql.js must be loaded asynchronously, whereas asm.js was able to be loaded synchronously.
Version 1.0 of sql.js must be loaded asynchronously, whereas asm.js was able to be loaded synchronously.

So in the past, you would:
```html
Expand Down Expand Up @@ -260,7 +260,7 @@ initSqlJs().then(function(SQL){
`NOTHING` is now a reserved word in SQLite, whereas previously it was not. This could cause errors like `Error: near "nothing": syntax error`

### Downloading/Using: ###
Although asm.js files were distributed as a single Javascript file, WebAssembly libraries are most efficiently distributed as a pair of files, the `.js` loader and the `.wasm` file, like [dist/sql-wasm.js]([dist/sql-wasm.js]) and [dist/sql-wasm.wasm]([dist/sql-wasm.wasm]). The `.js` file is responsible for wrapping/loading the `.wasm` file.
Although asm.js files were distributed as a single Javascript file, WebAssembly libraries are most efficiently distributed as a pair of files, the `.js` loader and the `.wasm` file, like [dist/sql-wasm.js]([dist/sql-wasm.js]) and [dist/sql-wasm.wasm]([dist/sql-wasm.wasm]). The `.js` file is responsible for wrapping/loading the `.wasm` file.



Expand Down
9 changes: 5 additions & 4 deletions examples/start_local_server.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env python

import BaseHTTPServer, SimpleHTTPServer, os

# We need to host from the root because we are going to be requesting files inside of dist
os.chdir('../')
port=8081
print "Running on port %d" % port

SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map['.wasm'] = 'application/wasm'

httpd = BaseHTTPServer.HTTPServer(('localhost', port), SimpleHTTPServer.SimpleHTTPRequestHandler)

print "Mapping \".wasm\" to \"%s\"" % SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map['.wasm']
httpd.serve_forever()
httpd.serve_forever()
2 changes: 1 addition & 1 deletion src/api-data.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ SQLite.TEXT=3
SQLite.BLOB=4
SQLite.NULL=5

# Encodings, used for registering functions.
# Encodings, used for registering functions.
SQLite.UTF8=1
4 changes: 2 additions & 2 deletions src/api.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class Database
try
# Store the SQL string in memory. The string will be consumed, one statement
# at a time, by sqlite3_prepare_v2_sqlptr.
# Note that if we want to allocate as much memory as could _possibly_ be used, we can
# Note that if we want to allocate as much memory as could _possibly_ be used, we can
# we allocate bytes equal to 4* the number of chars in the sql string.
# It would be faster, but this is probably a premature optimization
nextSqlPtr = allocateUTF8OnStack(sql)
Expand Down Expand Up @@ -490,7 +490,7 @@ class Database
sqlite3_result_error(cx,error,-1)
return

# Return the result of the user defined function to SQLite
# Return the result of the user defined function to SQLite
switch typeof(result)
when 'boolean' then sqlite3_result_int(cx,if result then 1 else 0)
when 'number' then sqlite3_result_double(cx, result)
Expand Down
1 change: 0 additions & 1 deletion src/exported_runtime_methods.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
"stackSave",
"stackRestore"
]

1 change: 0 additions & 1 deletion src/shell-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ else if (typeof define === 'function' && define['amd']) {
else if (typeof exports === 'object'){
exports["Module"] = initSqlJs;
}

2 changes: 1 addition & 1 deletion src/shell-pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ var initSqlJs = function (moduleConfig) {
// of the options, and has the side effect of reducing emcc's efforts to modify the module if its output were to change in the future.
// That's a nice side effect since we're handling the modularization efforts ourselves
module = undefined;

// The emcc-generated code and shell-post.js code goes below,
// meaning that all of it runs inside of this promise. If anything throws an exception, our promise will abort

0 comments on commit 86865e6

Please sign in to comment.