FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[RFC] support build with custom (non-standard) functions by brody2consult · Pull Request #320 · sql-js/sql.js · GitHub

/ sql.js Public
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .coffee  (2) .json  (1) No extension  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 5 additions & 1 deletion Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ EMFLAGS_DEBUG = \
-s ASSERTIONS=1 \
-O1

BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc
BITCODE_FILES = out/sqlite3.bc out/extension-functions.bc out/custom_extensions.bc

OUTPUT_WRAPPER_FILES = src/shell-pre.js src/shell-post.js

Expand Down Expand Up @@ -160,6 +160,10 @@ out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTI
mkdir -p out
$(EMCC) $(CFLAGS) -s LINKABLE=1 sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@

out/custom_extensions.bc: src/custom_extensions/custom_extensions.c
mkdir -p out
$(EMCC) $(CFLAGS) -Isqlite-src/$(SQLITE_AMALGAMATION) -s LINKABLE=1 $^ -o $@

# TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder
# module.tar.gz: test package.json AUTHORS README.md dist/sql-asm.js
# tar --create --gzip $^ > $@
Expand Down
6 changes: 6 additions & 0 deletions src/api.coffee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,13 @@ class Database
constructor: (data) ->
@filename = 'dbfile_' + (0xffffffff*Math.random()>>>0)
if data? then FS.createDataFile '/', @filename, data, true, true
# open the database and register extension functions
@handleError sqlite3_open @filename, apiTemp
@db = getValue(apiTemp, 'i32')
# register built-in extension functions:
RegisterExtensionFunctions(@db)
# register any custom (non-standard) extension functions:
custom_extensions(@db)
@statements = {} # A list of all prepared statements of the database
@functions = {} # A list of all user function of the database (created by create_function call)

Expand Down Expand Up @@ -404,6 +408,8 @@ class Database
@functions={}
@handleError sqlite3_close_v2 @db
binaryDb = FS.readFile @filename, encoding:'binary'
# just open the database
# (no need to register extension functions)
@handleError sqlite3_open @filename, apiTemp
@db = getValue apiTemp, 'i32'
binaryDb
Expand Down
8 changes: 8 additions & 0 deletions src/custom_extensions/custom_extensions.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "sqlite3.h"

/** FUTURE TBD Build this module with any custom extension module(s) included */

int custom_extensions(sqlite3 * db)
{
return SQLITE_OK;
}
1 change: 1 addition & 0 deletions src/exported_functions.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"_sqlite3_result_int",
"_sqlite3_result_int64",
"_sqlite3_result_error",
"_custom_extensions",
"_RegisterExtensionFunctions"
]
3 changes: 3 additions & 0 deletions src/exports.coffee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ sqlite3_result_int64 = Module['cwrap'] 'sqlite3_result_int64', '', ['number', 'n
sqlite3_result_error = Module['cwrap'] 'sqlite3_result_error', '', ['number', 'string', 'number']
RegisterExtensionFunctions = Module['cwrap'] 'RegisterExtensionFunctions', 'number', ['number']

## Support custom db extensions
custom_extensions = Module['cwrap'] 'custom_extensions', 'number', ['number']

# Export the API
this['SQL'] = {'Database':Database}
Module[i] = this['SQL'][i] for i of this['SQL']

Back | FazBrowse Home | New Git URL