Initial commit
This commit is contained in:
commit
d104a77bcf
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
.jshintrc
|
53
README.md
Normal file
53
README.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# PawSQLite WebSQL Adapter
|
||||||
|
|
||||||
|
A WebSQL adapter for PawSQLite which offers many improvements over working with WebSQL natively. Most importantly, transactions do not commit automatically. This allows you to perform asynchronous operations during transactions and still guarantee data integrity.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
You can install using npm:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install -s git+https://git.n0m.org/n0m/PawSQLite.git
|
||||||
|
npm install -s git+https://git.n0m.org/n0m/PawSQLite-WebSQL-Adapter.git
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
For more detailed usage, please see: [https://git.n0m.org/n0m/PawSQLite](https://git.n0m.org/n0m/PawSQLite)
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const PawSQLite = require("pawsqlite");
|
||||||
|
const PawSQLiteWebSQLAdapter = require("pawsqlite-websql-adapter");
|
||||||
|
|
||||||
|
PawSQLite.registerAdapter(PawSQLiteWebSQLAdapter)
|
||||||
|
|
||||||
|
const db = await PawSQLite.open("test", {
|
||||||
|
adapter: 'PawSQLiteWebSQLAdapter'
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.sql(`
|
||||||
|
CREATE TABLE contacts (
|
||||||
|
contact_id INTEGER PRIMARY KEY,
|
||||||
|
first_name TEXT NOT NULL,
|
||||||
|
last_name TEXT NOT NULL
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
const transaction = db.transaction();
|
||||||
|
|
||||||
|
console.log(await db.sql("SELECT * FROM contacts"));
|
||||||
|
|
||||||
|
await transaction.sql(
|
||||||
|
"INSERT INTO contacts (first_name, last_name) VALUES (?, ?)",
|
||||||
|
"John",
|
||||||
|
"Lennon"
|
||||||
|
);
|
||||||
|
|
||||||
|
await transaction.commit();
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
||||||
|
|
||||||
|
## License
|
||||||
|
[MIT](https://choosealicense.com/licenses/mit/)
|
168
lib/pawsqlite-node-adapter.js
Normal file
168
lib/pawsqlite-node-adapter.js
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
/******/ (() => { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/ var __webpack_modules__ = ({
|
||||||
|
|
||||||
|
/***/ "./src/log.mjs":
|
||||||
|
/*!*********************!*\
|
||||||
|
!*** ./src/log.mjs ***!
|
||||||
|
\*********************/
|
||||||
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||||
|
/* harmony export */ "log": () => (/* binding */ log),
|
||||||
|
/* harmony export */ "enableDebug": () => (/* binding */ enableDebug)
|
||||||
|
/* harmony export */ });
|
||||||
|
let DEBUG = false;
|
||||||
|
|
||||||
|
function log(...args) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log(...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableDebug(active) {
|
||||||
|
DEBUG = !!active;
|
||||||
|
log("PawSQLite-WebSQL-Adapter: debugging " + (
|
||||||
|
DEBUG ? "enabled" : "disabled")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./src/node_adapter_error.mjs":
|
||||||
|
/*!************************************!*\
|
||||||
|
!*** ./src/node_adapter_error.mjs ***!
|
||||||
|
\************************************/
|
||||||
|
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||||
|
/* harmony export */ "NodeAdapterError": () => (/* binding */ NodeAdapterError)
|
||||||
|
/* harmony export */ });
|
||||||
|
class NodeAdapterError extends Error {
|
||||||
|
static from(e) {
|
||||||
|
let message = "";
|
||||||
|
if (e && e.message) {
|
||||||
|
message = e.message;
|
||||||
|
}
|
||||||
|
return new NodeAdapterError(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***/ })
|
||||||
|
|
||||||
|
/******/ });
|
||||||
|
/************************************************************************/
|
||||||
|
/******/ // The module cache
|
||||||
|
/******/ var __webpack_module_cache__ = {};
|
||||||
|
/******/
|
||||||
|
/******/ // The require function
|
||||||
|
/******/ function __webpack_require__(moduleId) {
|
||||||
|
/******/ // Check if module is in cache
|
||||||
|
/******/ if(__webpack_module_cache__[moduleId]) {
|
||||||
|
/******/ return __webpack_module_cache__[moduleId].exports;
|
||||||
|
/******/ }
|
||||||
|
/******/ // Create a new module (and put it into the cache)
|
||||||
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||||
|
/******/ // no module.id needed
|
||||||
|
/******/ // no module.loaded needed
|
||||||
|
/******/ exports: {}
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // Execute the module function
|
||||||
|
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||||||
|
/******/
|
||||||
|
/******/ // Return the exports of the module
|
||||||
|
/******/ return module.exports;
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/************************************************************************/
|
||||||
|
/******/ /* webpack/runtime/define property getters */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ // define getter functions for harmony exports
|
||||||
|
/******/ __webpack_require__.d = (exports, definition) => {
|
||||||
|
/******/ for(var key in definition) {
|
||||||
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
||||||
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
||||||
|
/******/ }
|
||||||
|
/******/ }
|
||||||
|
/******/ };
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/******/ /* webpack/runtime/make namespace object */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ // define __esModule on exports
|
||||||
|
/******/ __webpack_require__.r = (exports) => {
|
||||||
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||||
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||||
|
/******/ }
|
||||||
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
/******/ };
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/************************************************************************/
|
||||||
|
var __webpack_exports__ = {};
|
||||||
|
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
||||||
|
(() => {
|
||||||
|
/*!******************************!*\
|
||||||
|
!*** ./src/node_adapter.mjs ***!
|
||||||
|
\******************************/
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||||
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
||||||
|
/* harmony export */ });
|
||||||
|
/* harmony import */ var _node_adapter_error_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./node_adapter_error.mjs */ "./src/node_adapter_error.mjs");
|
||||||
|
/* harmony import */ var _log_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./log.mjs */ "./src/log.mjs");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const databases = new Map();
|
||||||
|
|
||||||
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
|
||||||
|
name: "PawSQLiteNodeAdapter",
|
||||||
|
open: async (dbName) => {
|
||||||
|
// const version = "1.0";
|
||||||
|
|
||||||
|
// if (!databases.has(dbName)) {
|
||||||
|
// databases.set(dbName, new DatabaseWrapper(dbName, version));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return ResponseWrapper.success({ version });
|
||||||
|
},
|
||||||
|
|
||||||
|
close: async (dbName) => {
|
||||||
|
// databases.delete(dbName);
|
||||||
|
// return ResponseWrapper.success();
|
||||||
|
},
|
||||||
|
|
||||||
|
sql: async (dbName, sql, ...args) => {
|
||||||
|
// log(sql);
|
||||||
|
|
||||||
|
// const db = databases.get(dbName);
|
||||||
|
// if (!db) {
|
||||||
|
// throw new NodeAdapterError("Database not open");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const result = await db.sql(sql, ...args);
|
||||||
|
// return ResponseWrapper.success(result);
|
||||||
|
},
|
||||||
|
|
||||||
|
delete: async (dbName) => {
|
||||||
|
// throw new NodeAdapterError("Delete not implemented");
|
||||||
|
},
|
||||||
|
|
||||||
|
debug: _log_mjs__WEBPACK_IMPORTED_MODULE_1__.enableDebug
|
||||||
|
});
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
module.exports = __webpack_exports__.default;
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
|
//# sourceMappingURL=pawsqlite-node-adapter.js.map
|
1
lib/pawsqlite-node-adapter.js.map
Normal file
1
lib/pawsqlite-node-adapter.js.map
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["webpack://pawsqlite-node-adapter/./src/log.mjs","webpack://pawsqlite-node-adapter/./src/node_adapter_error.mjs","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":";;;;;;;;;;;;;;;AAAA;;AAEO;AACP;AACA;AACA,G;AACA;;AAEO;AACP;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;;;ACbO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;;;;;;UCRA;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;AACf;;AAE7C;;AAEA,iEAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;;AAEA,uCAAuC,UAAU;AACjD,GAAG;;AAEH;AACA;AACA;AACA,GAAG;;AAEH;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,GAAG;;AAEH;AACA;AACA,GAAG;;AAEH,SAAS,iDAAW;AACpB,CAAC,EAAC","file":"pawsqlite-node-adapter.js","sourcesContent":["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-WebSQL-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}","// 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 { enableDebug, log } from \"./log.mjs\";\n\nconst databases = new Map();\n\nexport default {\n name: \"PawSQLiteNodeAdapter\",\n open: async (dbName) => {\n // const version = \"1.0\";\n\n // if (!databases.has(dbName)) {\n // databases.set(dbName, new DatabaseWrapper(dbName, version));\n // }\n\n // return ResponseWrapper.success({ version });\n },\n\n close: async (dbName) => {\n // databases.delete(dbName);\n // return ResponseWrapper.success();\n },\n\n sql: async (dbName, sql, ...args) => {\n // log(sql);\n\n // const db = databases.get(dbName);\n // if (!db) {\n // throw new NodeAdapterError(\"Database not open\");\n // }\n\n // const result = await db.sql(sql, ...args);\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"],"sourceRoot":""}
|
1030
package-lock.json
generated
Normal file
1030
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
package.json
Normal file
20
package.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "pawsqlite-node-adapter",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A Node.js adapter for PawSQLite",
|
||||||
|
"main": "./lib/pawsqlite-node-adapter.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"build": "webpack"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.n0m.org/n0m/PawSQLite-Node-Adapter.git"
|
||||||
|
},
|
||||||
|
"author": "Ben Ashton",
|
||||||
|
"license": "MIT",
|
||||||
|
"devDependencies": {
|
||||||
|
"webpack": "5.x",
|
||||||
|
"webpack-cli": "4.x"
|
||||||
|
}
|
||||||
|
}
|
14
src/log.mjs
Normal file
14
src/log.mjs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
let DEBUG = false;
|
||||||
|
|
||||||
|
export function log(...args) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log(...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function enableDebug(active) {
|
||||||
|
DEBUG = !!active;
|
||||||
|
log("PawSQLite-WebSQL-Adapter: debugging " + (
|
||||||
|
DEBUG ? "enabled" : "disabled")
|
||||||
|
);
|
||||||
|
}
|
40
src/node_adapter.mjs
Normal file
40
src/node_adapter.mjs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { NodeAdapterError } from "./node_adapter_error.mjs";
|
||||||
|
import { enableDebug, log } from "./log.mjs";
|
||||||
|
|
||||||
|
const databases = new Map();
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "PawSQLiteNodeAdapter",
|
||||||
|
open: async (dbName) => {
|
||||||
|
// const version = "1.0";
|
||||||
|
|
||||||
|
// if (!databases.has(dbName)) {
|
||||||
|
// databases.set(dbName, new DatabaseWrapper(dbName, version));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return ResponseWrapper.success({ version });
|
||||||
|
},
|
||||||
|
|
||||||
|
close: async (dbName) => {
|
||||||
|
// databases.delete(dbName);
|
||||||
|
// return ResponseWrapper.success();
|
||||||
|
},
|
||||||
|
|
||||||
|
sql: async (dbName, sql, ...args) => {
|
||||||
|
// log(sql);
|
||||||
|
|
||||||
|
// const db = databases.get(dbName);
|
||||||
|
// if (!db) {
|
||||||
|
// throw new NodeAdapterError("Database not open");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const result = await db.sql(sql, ...args);
|
||||||
|
// return ResponseWrapper.success(result);
|
||||||
|
},
|
||||||
|
|
||||||
|
delete: async (dbName) => {
|
||||||
|
// throw new NodeAdapterError("Delete not implemented");
|
||||||
|
},
|
||||||
|
|
||||||
|
debug: enableDebug
|
||||||
|
};
|
9
src/node_adapter_error.mjs
Normal file
9
src/node_adapter_error.mjs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export class NodeAdapterError extends Error {
|
||||||
|
static from(e) {
|
||||||
|
let message = "";
|
||||||
|
if (e && e.message) {
|
||||||
|
message = e.message;
|
||||||
|
}
|
||||||
|
return new NodeAdapterError(message);
|
||||||
|
}
|
||||||
|
}
|
17
webpack.config.js
Normal file
17
webpack.config.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
var webpack = require('webpack');
|
||||||
|
var libraryName = 'pawsqlite-node-adapter';
|
||||||
|
var outputFile = libraryName + '.js';
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
mode: 'development',
|
||||||
|
entry: __dirname + '/src/node_adapter.mjs',
|
||||||
|
devtool: 'source-map',
|
||||||
|
output: {
|
||||||
|
path: __dirname + '/lib',
|
||||||
|
filename: outputFile,
|
||||||
|
libraryExport: 'default',
|
||||||
|
libraryTarget: 'commonjs2',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = config;
|
Loading…
Reference in New Issue
Block a user