sqlite-worker
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -12,7 +12,11 @@ 'use strict'; | ||
assign(indexedDB.open(name, version), { | ||
onupgradeneeded({target: {result}}) { | ||
onupgradeneeded({target: {result, transaction}}) { | ||
if (!result.objectStoreNames.contains(STORE)) | ||
result.createObjectStore(STORE) | ||
.createIndex(keyPath, keyPath, {unique: true}); | ||
resolve(result); | ||
assign(transaction, { | ||
oncomplete() { | ||
resolve(result); | ||
} | ||
}); | ||
}, | ||
@@ -27,10 +31,12 @@ onsuccess({target: {result}}) { | ||
const init = (options = {}) => new Promise((resolve, onerror) => { | ||
// const {url} = ({url: require('url').pathToFileURL(__filename).href}); | ||
const dir = options.dir || 'https://sql.js.org/dist'; // url.slice(0, url.lastIndexOf('/')); | ||
Promise.all([ | ||
opener(options.name || 'sqlite-worker'), | ||
initSqlJs({ | ||
locateFile: file => (options.dir || 'https://sql.js.org/dist') + '/' + file | ||
locateFile: file => dir + '/' + file | ||
}) | ||
]).then( | ||
([idb, {Database}]) => { | ||
const store = how => idb.transaction([STORE], how).objectStore(STORE); | ||
([iDB, {Database}]) => { | ||
const store = how => iDB.transaction([STORE], how).objectStore(STORE); | ||
assign(store('readonly').get(keyPath), { | ||
@@ -37,0 +43,0 @@ onsuccess() { |
@@ -11,7 +11,11 @@ import SQLiteTag from 'sqlite-tag'; | ||
assign(indexedDB.open(name, version), { | ||
onupgradeneeded({target: {result}}) { | ||
onupgradeneeded({target: {result, transaction}}) { | ||
if (!result.objectStoreNames.contains(STORE)) | ||
result.createObjectStore(STORE) | ||
.createIndex(keyPath, keyPath, {unique: true}); | ||
resolve(result); | ||
assign(transaction, { | ||
oncomplete() { | ||
resolve(result); | ||
} | ||
}); | ||
}, | ||
@@ -26,10 +30,12 @@ onsuccess({target: {result}}) { | ||
export const init = (options = {}) => new Promise((resolve, onerror) => { | ||
// const {url} = import.meta; | ||
const dir = options.dir || 'https://sql.js.org/dist'; // url.slice(0, url.lastIndexOf('/')); | ||
Promise.all([ | ||
opener(options.name || 'sqlite-worker'), | ||
initSqlJs({ | ||
locateFile: file => (options.dir || 'https://sql.js.org/dist') + '/' + file | ||
locateFile: file => dir + '/' + file | ||
}) | ||
]).then( | ||
([idb, {Database}]) => { | ||
const store = how => idb.transaction([STORE], how).objectStore(STORE); | ||
([iDB, {Database}]) => { | ||
const store = how => iDB.transaction([STORE], how).objectStore(STORE); | ||
assign(store('readonly').get(keyPath), { | ||
@@ -36,0 +42,0 @@ onsuccess() { |
{ | ||
"name": "sqlite-worker", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "A simple, and persistent, SQLite database for Web and Workers", | ||
@@ -8,3 +8,3 @@ "main": "./cjs/index.js", | ||
"build": "npm run import && npm run cjs && npm run rollup:es", | ||
"import": "terser node_modules/sql.js/dist/sql-wasm-debug.js -m -o esm/sql-wasm.js && sed -i 's/module=undefined;/var module=void 0;/' esm/sql-wasm.js && echo ';export default initSqlJs;' >> esm/sql-wasm.js", | ||
"import": "cp node_modules/sql.js/dist/sql-wasm-debug.wasm esm/ && terser node_modules/sql.js/dist/sql-wasm-debug.js -m -o esm/sql-wasm.js && sed -i 's/module=undefined;/self.module=undefined;/' esm/sql-wasm.js && echo ';export default initSqlJs;' >> esm/sql-wasm.js", | ||
"cjs": "ascjs --no-default esm cjs", | ||
@@ -11,0 +11,0 @@ "rollup:es": "rollup --config rollup/es.config.js && sed -i.bck 's/^var /self./' es.js && rm -rf es.js.bck" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1606505
14
1716