diff --git a/src/api.coffee b/src/api.coffee index 9599ccfe..4a3f9eed 100644 --- a/src/api.coffee +++ b/src/api.coffee @@ -235,11 +235,15 @@ class Statement # Represents an SQLite database class Database # 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 data [Array] An array of bytes representing an SQLite database file - constructor: (data) -> + # either stored in the byte array or at the URL passed in first argument + # @param dataOrURL [Array, String] An array of bytes representing an SQLite database file or the URL to the database file + constructor: (dataOrURL) -> @filename = 'dbfile_' + (0xffffffff*Math.random()>>>0) - if data? then FS.createDataFile '/', @filename, data, true, true + if dataOrURL? + if typeof dataOrURL is 'string' # URL + FS.createLazyFile '/', @filename, dataOrURL, true, true + else # Data + FS.createDataFile '/', @filename, dataOrURL, true, true @handleError sqlite3_open @filename, apiTemp @db = getValue(apiTemp, 'i32') RegisterExtensionFunctions(@db) diff --git a/src/worker.coffee b/src/worker.coffee index 281d123d..15c9e9f7 100644 --- a/src/worker.coffee +++ b/src/worker.coffee @@ -14,7 +14,13 @@ if typeof importScripts is 'function' # Detect webworker context switch data?['action'] when 'open' buff = data['buffer'] - createDb (if buff then new Uint8Array(buff) else undefined) + url = data['url'] + if buff + createDb (new Uint8Array(buff)) + else if url + createDb url + else + createDb undefined postMessage 'id': data['id'] 'ready': true