1 line
8.0 KiB
Plaintext
1 line
8.0 KiB
Plaintext
{"version":3,"sources":["webpack://pawsqlite-node-adapter/./src/database_wrapper.mjs","webpack://pawsqlite-node-adapter/./src/log.mjs","webpack://pawsqlite-node-adapter/./src/node_adapter_error.mjs","webpack://pawsqlite-node-adapter/./src/query_wrapper.mjs","webpack://pawsqlite-node-adapter/./src/response_wrapper.mjs","webpack://pawsqlite-node-adapter/external \"sqlite3\"","webpack://pawsqlite-node-adapter/webpack/bootstrap","webpack://pawsqlite-node-adapter/webpack/runtime/define property getters","webpack://pawsqlite-node-adapter/webpack/runtime/hasOwnProperty shorthand","webpack://pawsqlite-node-adapter/webpack/runtime/make namespace object","webpack://pawsqlite-node-adapter/./src/node_adapter.mjs"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAmC;;AAEyB;AACT;AACnB;;;AAGzB;AACP;AACA;AACA;;AAEA;AACA;AACA,qBAAqB,6CAAgB;AACrC;AACA,QAAQ,mDAAsB,GAAG,gDAAmB;AACpD;AACA;AACA,mBAAmB,0EAAqB;AACxC;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA,iBAAiB,0EAAqB;AACtC;AACA;AACA;AACA,OAAO;AACP,KAAK;AACL;;AAEA;AACA,sBAAsB,4DAAY;AAClC;AACA;;AAEA,C;;;;;;;;;;;;;;;AC9CA;;AAEO;AACP;AACA;AACA,G;AACA;;AAEO;AACP;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;;;ACbO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;;;;;;ACR4D;AACH;AACzB;;;AAGzB;AACP;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;AACA;;AAEA,MAAM,6CAAG;AACT;AACA;AACA,iBAAiB,0EAAqB;AACtC;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,gBAAgB,0EAAuB;AACvC,OAAO;AACP,KAAK;AACL;;AAEA;AACA;AACA,MAAM,6CAAG;AACT;AACA;AACA,iBAAiB,0EAAqB;AACtC;AACA;AACA,gBAAgB,0EAAuB,EAAE,KAAK;AAC9C,OAAO;AACP,KAAK;AACL;AACA,C;;;;;;;;;;;;;;ACnEO;AACP,oBAAoB;AACpB;AACA;AACA,GAAG;AACH,E;;;;;;;;;;ACLA,qC;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCrBA;WACA;WACA;WACA;WACA,wCAAwC,yCAAyC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,sDAAsD,kBAAkB;WACxE;WACA,+CAA+C,cAAc;WAC7D,E;;;;;;;;;;;;;;;;;;ACN4D;AACH;AACA;AACZ;;AAE7C;;AAEO;AACP;AACA;AACA;AACA,qBAAqB,kEAAe;AACpC;AACA;AACA;;AAEA,WAAW,0EAAuB;AAClC,GAAG;;AAEH;AACA;AACA;AACA;;AAEA,WAAW,0EAAuB;AAClC,GAAG;;AAEH;AACA;AACA;;AAEA,WAAW,0EAAuB;AAClC,GAAG;;AAEH;AACA,cAAc,qEAAgB;AAC9B,GAAG;;AAEH,SAAS,iDAAW;AACpB;;;AAGA;AACA;AACA;AACA,cAAc,qEAAgB;AAC9B;AACA;AACA,C","file":"pawsqlite-node-adapter.js","sourcesContent":["import * as sqlite3 from \"sqlite3\";\n\nimport { NodeAdapterError } from \"./node_adapter_error.mjs\";\nimport { QueryWrapper } from \"./query_wrapper.mjs\";\nimport { log } from \"./log.mjs\";\n\n\nexport class DatabaseWrapper {\n constructor(dbName) {\n this.dbName = dbName;\n }\n\n open() {\n return new Promise((resolve, reject) => {\n const db = new sqlite3.Database(\n this.dbName,\n sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE,\n (err) => {\n if (err) {\n reject(NodeAdapterError.from(err));\n return;\n }\n this.db = db;\n resolve();\n }\n );\n });\n }\n\n close() {\n return new Promise((resolve, reject) => {\n this.db.close((err) => {\n if (err) {\n reject(NodeAdapterError.from(err));\n return;\n }\n resolve();\n });\n });\n }\n\n sql(sql, ...args) {\n const query = new QueryWrapper(sql, ...args);\n return query.execute(this.db);\n }\n\n}","let DEBUG = false;\n\nexport function log(...args) {\n if (DEBUG) {\n console.log(...args);\n } \n}\n\nexport function enableDebug(active) {\n DEBUG = !!active;\n log(\"PawSQLite-Node-Adapter: debugging \" + (\n DEBUG ? \"enabled\" : \"disabled\")\n );\n}","export class NodeAdapterError extends Error {\n static from(e) {\n let message = \"\";\n if (e && e.message) {\n message = e.message;\n }\n return new NodeAdapterError(message);\n }\n}","import { NodeAdapterError } from \"./node_adapter_error.mjs\";\nimport { ResponseWrapper } from \"./response_wrapper.mjs\";\nimport { log } from \"./log.mjs\";\n\n\nexport class QueryWrapper {\n constructor(sql, ...args) {\n this.sql = sql.trim();\n this.args = args;\n this.operation = sql.replace(/[^a-z].*/i, \"\").toUpperCase();\n }\n\n isAnyOf(...operations) {\n for (const op of operations) {\n if(op.toUpperCase() === this.operation) {\n return true;\n }\n }\n return false;\n }\n\n execute(db) {\n if (this.isAnyOf(\"INSERT\", \"UPDATE\", \"DELETE\")) {\n return this.executeRun(db);\n } else {\n return this.executeAll(db);\n }\n }\n\n executeRun(db) {\n return new Promise((resolve, reject) => {\n const self = this;\n\n log(this.sql);\n db.run(this.sql, ...this.args, function (err) {\n if (err) {\n reject(NodeAdapterError.from(err));\n return;\n }\n\n const result = {};\n\n if (self.isAnyOf(\"INSERT\")) {\n result.insertId = this.lastID;\n }\n\n if (self.isAnyOf(\"UPDATE\", \"DELETE\")) {\n result.rowsAffected = this.changes;\n }\n\n resolve(ResponseWrapper.success(result));\n });\n });\n }\n\n executeAll(db) {\n return new Promise((resolve, reject) => {\n log(this.sql);\n db.all(this.sql, ...this.args, function (err, rows) {\n if (err) {\n reject(NodeAdapterError.from(err));\n return;\n }\n resolve(ResponseWrapper.success({rows}));\n });\n });\n }\n}","export const ResponseWrapper = {\n success: (obj = {}) => ({\n success: true,\n ...obj\n })\n};","module.exports = require(\"sqlite3\");;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { NodeAdapterError } from \"./node_adapter_error.mjs\";\nimport { DatabaseWrapper } from \"./database_wrapper.mjs\";\nimport { ResponseWrapper } from \"./response_wrapper.mjs\";\nimport { enableDebug, log } from \"./log.mjs\";\n\nconst databases = new Map();\n\nexport const PawSQLiteNodeAdapter = {\n name: \"PawSQLiteNodeAdapter\",\n open: async (dbName) => {\n if (!databases.has(dbName)) {\n const db = new DatabaseWrapper(dbName);\n await db.open();\n databases.set(dbName, db);\n }\n\n return ResponseWrapper.success();\n },\n\n close: async (dbName) => {\n const db = getDatabase(dbName);\n await db.close();\n databases.delete(dbName);\n\n return ResponseWrapper.success();\n },\n\n sql: async (dbName, sql, ...args) => {\n const db = getDatabase(dbName);\n const result = await db.sql(sql, ...args);\n\n return ResponseWrapper.success(result);\n },\n\n delete: async (dbName) => {\n throw new NodeAdapterError(\"Delete not implemented\");\n },\n\n debug: enableDebug\n};\n\n\nfunction getDatabase(dbName) {\n const db = databases.get(dbName);\n if (!db) {\n throw new NodeAdapterError(\"Database not open\");\n }\n return db;\n}"],"sourceRoot":""} |