Skip to content

Commit ad89e3f

Browse files
committed
custom database constructor and export FS api
1 parent f65fa15 commit ad89e3f

File tree

5 files changed

+9
-25
lines changed

5 files changed

+9
-25
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/node_modules
22
/dist
3-
/data
3+
/data

sql.js/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ CFLAGS = \
2121
-O2 \
2222
-DSQLITE_OMIT_LOAD_EXTENSION \
2323
-DSQLITE_DISABLE_LFS \
24+
-DSQLITE_ENABLE_FTS3 \
25+
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
2426
-DSQLITE_ENABLE_FTS5 \
2527
-DSQLITE_ENABLE_JSON1 \
2628
-DSQLITE_THREADSAFE=0 \

sql.js/dist/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gitignore

sql.js/src/api.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
324324
}
325325
return true;
326326
};
327-
Statement.prototype["bind2"] = Statement.prototype.bind; // https://github.com/GoogleChromeLabs/comlink/blob/4ba8162f6c28fb1bf53b491565ef9a3ae42b72d3/src/comlink.ts#L432
327+
Statement.prototype["bind_"] = Statement.prototype.bind; // work around https://github.com/GoogleChromeLabs/comlink/blob/4ba8162f6c28fb1bf53b491565ef9a3ae42b72d3/src/comlink.ts#L432
328328

329329
/** Execute the statement, fetching the the next line of result,
330330
that can be retrieved with {@link Statement.get}.
@@ -792,7 +792,6 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
792792
if (data != null) {
793793
FS.createDataFile("/", this.filename, data, true, true);
794794
}
795-
const READONLY = 1;
796795
const ret = sqlite3_open(this.filename, apiTemp);
797796
this.db = getValue(apiTemp, "i32");
798797
this.handleError(ret);
@@ -803,24 +802,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
803802
// (created by create_function call)
804803
this.functions = {};
805804
}
806-
function VfsDatabase(filename, vfs) {
807-
this.filename = filename;
808-
const READONLY = 1;
809-
const ret = sqlite3_open_v2(this.filename, apiTemp, 1, vfs);
810-
this.db = getValue(apiTemp, "i32");
811-
this.handleError(ret);
812-
registerExtensionFunctions(this.db);
813-
// A list of all prepared statements of the database
814-
this.statements = {};
815-
// A list of all user function of the database
816-
// (created by create_function call)
817-
this.functions = {};
818-
}
819805

820-
function UrlDatabase(filename, lazyFile) {
806+
function CustomDatabase(filename) {
821807
this.filename = filename;
822-
this.lazyFile = lazyFile;
823-
const ret = sqlite3_open(this.filename, apiTemp, 1, null);
808+
const ret = sqlite3_open(this.filename, apiTemp);
824809
this.db = getValue(apiTemp, "i32");
825810
this.handleError(ret);
826811
registerExtensionFunctions(this.db);
@@ -1231,9 +1216,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
12311216

12321217
// export Database to Module
12331218
Module.Database = Database;
1234-
Module["VfsDatabase"] = VfsDatabase;
1235-
Module["UrlDatabase"] = UrlDatabase;
1219+
Module["CustomDatabase"] = CustomDatabase;
12361220
Module["FS"] = FS;
1237-
VfsDatabase.prototype = Object.create(Database.prototype);
1238-
UrlDatabase.prototype = Object.create(Database.prototype);
1221+
CustomDatabase.prototype = Object.create(Database.prototype);
12391222
};

sql.js/src/exported_functions.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"_malloc",
33
"_free",
44
"_sqlite3_open",
5-
"_sqlite3_open_v2",
65
"_sqlite3_exec",
76
"_sqlite3_free",
87
"_sqlite3_errmsg",
@@ -42,6 +41,5 @@
4241
"_sqlite3_result_int",
4342
"_sqlite3_result_int64",
4443
"_sqlite3_result_error",
45-
"_sqlite3_vfs_register",
4644
"_RegisterExtensionFunctions"
4745
]

0 commit comments

Comments
 (0)