Skip to content
Open
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
12 changes: 8 additions & 4 deletions src/api.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer>] 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<Integer>, 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)
Expand Down
8 changes: 7 additions & 1 deletion src/worker.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down