@yhwh-script/sqlite 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -3,7 +3,7 @@ import sqlite3InitModule from '@sqlite.org/sqlite-wasm';
3
3
  // https://www.npmjs.com/package/@sqlite.org/sqlite-wasm
4
4
  // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
5
5
 
6
- export const moduleName = "sqlite";
6
+ export const name = "sqlite";
7
7
 
8
8
  const workers = {};
9
9
 
package/package.json CHANGED
@@ -26,5 +26,5 @@
26
26
  "url": "git+https://github.com/yhwh-script/sqlite.git"
27
27
  },
28
28
  "type": "module",
29
- "version": "2.0.0"
29
+ "version": "2.0.2"
30
30
  }
package/sqliteWorker.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import sqlite3InitModule from '@sqlite.org/sqlite-wasm';
2
- import { log, info, error } from '../logger';
3
2
 
4
3
  var db = null;
5
4
  var sqlite3 = null;
@@ -22,10 +21,10 @@ onmessage = async function ({ data }) {
22
21
  postMessage({ result, type: "application/json" });
23
22
  } catch (e) {
24
23
  if (e.message.indexOf("SQLITE_CANTOPEN") != -1) {
25
- info("Info: Currently no SQLite database available for this worker. Upload a new database or reload the page.");
24
+ console.info("Info: Currently no SQLite database available for this worker. Upload a new database or reload the page.");
26
25
  }
27
26
  if (e.message.indexOf("SQLITE_CONSTRAINT_UNIQUE") != -1) {
28
- error("Error executing SQL statement", sql, e.message);
27
+ console.error("Error executing SQL statement", sql, e.message);
29
28
  }
30
29
  }
31
30
  break;
@@ -34,12 +33,12 @@ onmessage = async function ({ data }) {
34
33
  const { sql, values } = data;
35
34
  let stmt;
36
35
  try {
37
- // console.log(sql, values);
36
+ // console.debug(sql, values);
38
37
  stmt = await db.prepare(sql, values);
39
38
  const columns = stmt.getColumnNames();
40
- // console.log("columns", columns);
39
+ // console.debug("columns", columns);
41
40
  stmt.bind(values);
42
- // console.log("stmt", stmt)
41
+ // console.debug("stmt", stmt)
43
42
  const result = [];
44
43
  while (stmt.step()) {
45
44
  let row = stmt.get([]);
@@ -49,15 +48,15 @@ onmessage = async function ({ data }) {
49
48
  let obj = Object.fromEntries(zipped);
50
49
  result.push(obj);
51
50
  }
52
- // console.log("RESULT", result)
51
+ // console.debug("RESULT", result)
53
52
  postMessage({ result, type: "application/json" });
54
53
  } catch (e) {
55
54
  if (e.message.indexOf("SQLITE_CANTOPEN") != -1) {
56
- info("Info: Currently no SQLite database available for this worker. Upload a new database or reload the page.");
55
+ console.info("Info: Currently no SQLite database available for this worker. Upload a new database or reload the page.");
57
56
  } else if (e.message.indexOf("SQLITE_CONSTRAINT_UNIQUE") != -1) {
58
- error("Error executing SQL statement", sql, e.message);
57
+ console.error("Error executing SQL statement", sql, e.message);
59
58
  } else {
60
- error("Error executing SQL statement", sql, e.message);
59
+ console.error("Error executing SQL statement", sql, e.message);
61
60
  }
62
61
  } finally {
63
62
  stmt.finalize();
@@ -67,7 +66,7 @@ onmessage = async function ({ data }) {
67
66
  case 'uploadDB':
68
67
  const { name, arrayBuffer } = data;
69
68
  const { message } = await uploadDatabase(name, arrayBuffer)
70
- log(message, db);
69
+ console.log(message, db);
71
70
  break;
72
71
  case 'downloadDB':
73
72
  try {
@@ -78,7 +77,7 @@ onmessage = async function ({ data }) {
78
77
  if (e.message.indexOf("SQLITE_NOMEM") != -1)
79
78
  postMessage({ type: "application/vnd.sqlite3", error: "SQLITE_NOMEM" });
80
79
  else
81
- error(e);
80
+ console.error(e);
82
81
  }
83
82
  break;
84
83
  case 'closeDB':
@@ -86,7 +85,7 @@ onmessage = async function ({ data }) {
86
85
  postMessage({ type: "closed" });
87
86
  break;
88
87
  default:
89
- log(data)
88
+ console.log(data)
90
89
  }
91
90
  }
92
91
 
@@ -112,13 +111,13 @@ async function uploadDatabase(name, arrayBuffer) {
112
111
  throw new Error({ name: "OPFSMissingError", message: "Unsupported operation due to missing OPFS support." });
113
112
  }
114
113
  } catch (err) {
115
- error(err.name, err.message);
114
+ console.error(err.name, err.message);
116
115
  }
117
116
  }
118
117
 
119
118
  function closeDB() {
120
119
  if (db) {
121
- log("Closing...", db);
120
+ console.log("Closing...", db);
122
121
  db.close();
123
122
  }
124
123
  }
@@ -126,10 +125,10 @@ function closeDB() {
126
125
  async function getInstance() {
127
126
  try {
128
127
  if (!sqlite3) {
129
- sqlite3 = await sqlite3InitModule({ print: log, printErr: error });
128
+ sqlite3 = await sqlite3InitModule({ print: console.log, printErr: console.error });
130
129
  }
131
130
  return sqlite3;
132
131
  } catch (err) {
133
- error(err.name, err.message);
132
+ console.error(err.name, err.message);
134
133
  }
135
134
  }