Skip to content

Add IDBFS support #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ EMFLAGS = \
-s EXPORTED_FUNCTIONS=@src/exported_functions.json \
-s EXTRA_EXPORTED_RUNTIME_METHODS=@src/exported_runtime_methods.json \
-s SINGLE_FILE=0 \
-s FORCE_FILESYSTEM=1 \
-lidbfs.js \
-s NODEJS_CATCH_EXIT=0

EMFLAGS_ASM = \
Expand All @@ -52,8 +54,7 @@ EMFLAGS_OPTIMIZED= \
-s INLINING_LIMIT=50 \
-O3 \
-flto \
--llvm-lto 1 \
--closure 1
--llvm-lto 1

EMFLAGS_DEBUG = \
-s INLINING_LIMIT=10 \
Expand Down
11 changes: 8 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,18 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
* @memberof module:SqlJs
* Open a new database either by creating a new one or opening an existing
* one stored in the byte array passed in first argument
* @param {number[]} data An array of bytes representing
* an SQLite database file
* @param {number[]|string} data An array of bytes representing
* an SQLite database file. Alternatively, a file path representing the
* file to load if using IDBFS.
*/
function Database(data) {
this.filename = "dbfile_" + (0xffffffff * Math.random() >>> 0);
if (data != null) {
FS.createDataFile("/", this.filename, data, true, true);
if (typeof data === "string") {
this.filename = data;
} else {
FS.createDataFile("/", this.filename, data, true, true);
}
}
this.handleError(sqlite3_open(this.filename, apiTemp));
this.db = getValue(apiTemp, "i32");
Expand Down
5 changes: 4 additions & 1 deletion src/exported_runtime_methods.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"cwrap",
"stackAlloc",
"stackSave",
"stackRestore"
"stackRestore",
"FS",
"MEMFS",
"IDBFS"
]