Skip to content

Commit

Permalink
added transaction support , jsstore version -2.2.1, using promise to …
Browse files Browse the repository at this point in the history
…execute multiple lines code
  • Loading branch information
ujjwalguptaofficial committed Jul 11, 2018
1 parent 7988111 commit ac89104
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 83 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"commander": "^2.15.1",
"express": "^4.16.3",
"fs-extra": "^6.0.1",
"jsstore": "^2.1.2",
"jsstore": "^2.2.1",
"loading-indicator": "^2.0.0",
"vue": "^2.5.13",
"vue-context-menu": "^2.0.6"
Expand Down
36 changes: 16 additions & 20 deletions src/code/component/query_executor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,22 @@ export default class QueryExecutor extends Vue {
evaluateAndShowResult(qry: string) {
var queryHelperInstance = new QueryHelper(qry);
if (queryHelperInstance.isQryValid()) {
const query = queryHelperInstance.getQuery();
if (queryHelperInstance.errMessage.length == 0) {
new MainService()
.executeQry(query)
.then(qryResult => {
this.showResultInfo = true;
this.resultCount =
Util.getType(qryResult.result) === DATA_TYPE.Array
? qryResult.result.length
: 0;
this.timeTaken = qryResult.timeTaken.toString();
vueEvent.$emit("on_qry_result", qryResult.result);
})
.catch(function(err) {
vueEvent.$emit("on_qry_error", err);
});
} else {
vueEvent.$emit("on_error", queryHelperInstance.errMessage);
}
if (queryHelperInstance.validateAndModifyQry()) {
const query = queryHelperInstance.query;
new MainService()
.executeQry(query)
.then(qryResult => {
this.showResultInfo = true;
this.resultCount =
Util.getType(qryResult.result) === DATA_TYPE.Array
? qryResult.result.length
: 0;
this.timeTaken = qryResult.timeTaken.toString();
vueEvent.$emit("on_qry_result", qryResult.result);
})
.catch(function(err) {
vueEvent.$emit("on_qry_error", err);
});
} else {
vueEvent.$emit("on_error", queryHelperInstance.errMessage);
}
Expand Down
1 change: 1 addition & 0 deletions src/code/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export enum API {
BulkInsert = "bulkInsert",
ExportJson = "exportJson",
ChangeLogStatus = "changeLogStatus",
Transaction = "transaction"
}
26 changes: 13 additions & 13 deletions src/code/helpers/query_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ export class QueryHelper {
this.query = query;
}

getQuery() {
validateAndModifyQry() {
var qry;
var isAnyApiFound = false;
this.allowedApi.forEach((api) => {
// every api call will have a open paranthesis after
const index = this.query.indexOf(api + "(");
if (index >= 0) {
isAnyApiFound = true;
this.query = `${this.query.substring(0, index)}this.connection.
this.query = `${this.query.substring(0, index)}con.
${this.query.substring(index, this.query.length)}`;
}
});
if (!isAnyApiFound) {
this.errMessage = "No valid api was found";
}
return this.query;
return !this.errMessage.length;
}

get allowedApi() {
Expand All @@ -36,19 +36,19 @@ export class QueryHelper {
API.Count,
API.DropDb,
API.BulkInsert,
API.ExportJson
API.ExportJson,
API.Transaction
];
}

isQryValid() {
const notAllowedKeywords = ["Instance", "then", "catch"];
notAllowedKeywords.every((item) => {
if (this.query.indexOf(item) >= 0) {
this.errMessage = `keyword: '${item}' is not allowed, only write code for api call`;
return false;
}
private isQryValid_() {
const fn = eval(this.query);
if (typeof fn.then === 'function') {
return true;
});
return !this.errMessage.length;
}
else {
this.errMessage = "The query should return a promise";
}
return false;
}
}
1 change: 1 addition & 0 deletions src/code/service/main_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class MainService extends BaseService {
if (Config.isLogEnabled === true) {
console.log("qry from service - " + query);
}
const con = this.connection;
return new Promise((resolve, reject) => {
var startTime = performance.now();
this.evaluateQry_(query).then(qryResult => {
Expand Down
6 changes: 4 additions & 2 deletions src/code/service/service_helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as JsStore from 'jsstore';
import * as workerPath from "file-loader?name=scripts/[name].[hash].js!jsstore/dist/jsstore.worker.min.js";
import * as workerPath from "file-loader?name=scripts/[name].[hash].js!jsstore/dist/jsstore.worker.js";

export class ServiceHelper {
static idbCon = new JsStore.Instance(new Worker(workerPath));
}
}

(window as any).con = ServiceHelper.idbCon;
2 changes: 1 addition & 1 deletion src/output/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta http-equiv="X-UA-Compatible" content="ie=edge"><meta name="keywords" content="idbstudio, jsstore, indexeddb, tools, idb"><meta name="description" content="idbstudio is a management tools for indexeddb library jsstore. It helps users to execute , debug and learn jsstore query."><meta name="robots" content="index, follow"><meta name="author" content="Ujjwal Gupta"><meta name="Revisit-After" content="1 days"><meta name="Rating" content="General"><meta property="og:title" content="IDBStudio"><meta property="og:type" content="IndexedDB management tool"><meta property="og:url" content="https://ujjwalguptaofficial.github.io/idbstudio/"><meta property="og:site_name" content="IDBStudio"><meta property="og:description" content="idbstudio is a management tools for indexeddb library jsstore. It helps users to execute , debug and learn jsstore query."><meta property="og:image" content="/img/JsStore_1200_630.png"><meta name="twitter:creator" content="@ujjwal_kr_gupta"><meta name="twitter:title" content="IDBStudio"><meta name="twitter:description" content="idbstudio is a management tools for indexeddb library jsstore. It helps users to execute , debug and learn jsstore query."><meta name="twitter:image" content="http://jsstore.net/img/JsStore_1200_630.png"><title>IDBStudio</title><link href="./assets/css/fontawesome-all.min.css" rel="stylesheet"><script src="./assets/scripts/ace.min.js"></script><script src="./assets/scripts/mode-javascript.js"></script></head><body><div id="app"></div><script src="scripts/bundle.js?3e7f3ead60fa3c9f587c"></script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta http-equiv="X-UA-Compatible" content="ie=edge"><meta name="keywords" content="idbstudio, jsstore, indexeddb, tools, idb"><meta name="description" content="idbstudio is a management tools for indexeddb library jsstore. It helps users to execute , debug and learn jsstore query."><meta name="robots" content="index, follow"><meta name="author" content="Ujjwal Gupta"><meta name="Revisit-After" content="1 days"><meta name="Rating" content="General"><meta property="og:title" content="IDBStudio"><meta property="og:type" content="IndexedDB management tool"><meta property="og:url" content="https://ujjwalguptaofficial.github.io/idbstudio/"><meta property="og:site_name" content="IDBStudio"><meta property="og:description" content="idbstudio is a management tools for indexeddb library jsstore. It helps users to execute , debug and learn jsstore query."><meta property="og:image" content="/img/JsStore_1200_630.png"><meta name="twitter:creator" content="@ujjwal_kr_gupta"><meta name="twitter:title" content="IDBStudio"><meta name="twitter:description" content="idbstudio is a management tools for indexeddb library jsstore. It helps users to execute , debug and learn jsstore query."><meta name="twitter:image" content="http://jsstore.net/img/JsStore_1200_630.png"><title>IDBStudio</title><link href="./assets/css/fontawesome-all.min.css" rel="stylesheet"><script src="./assets/scripts/ace.min.js"></script><script src="./assets/scripts/mode-javascript.js"></script></head><body><div id="app"></div><script src="scripts/bundle.js?378a89433bd31e65e065"></script></body></html>
94 changes: 53 additions & 41 deletions src/output/scripts/bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* @license :idbstudio - V1.2.1 - 10/06/2018
* @license :idbstudio - V1.2.2 - 11/07/2018
* https://github.com/ujjwalguptaofficial/idbstudio
* Copyright (c) 2018 @Ujjwal Gupta; Licensed APACHE-2.0
*/
Expand Down Expand Up @@ -11438,6 +11438,7 @@ var MainService = /** @class */ (function (_super) {
if (jsstore__WEBPACK_IMPORTED_MODULE_1__["Config"].isLogEnabled === true) {
console.log("qry from service - " + query);
}
var con = this.connection;
return new Promise(function (resolve, reject) {
var startTime = performance.now();
_this.evaluateQry_(query).then(function (qryResult) {
Expand Down Expand Up @@ -11511,25 +11512,26 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ServiceHelper", function() { return ServiceHelper; });
/* harmony import */ var jsstore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(35);
/* harmony import */ var jsstore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jsstore__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var file_loader_name_scripts_name_hash_js_jsstore_dist_jsstore_worker_min_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(36);
/* harmony import */ var file_loader_name_scripts_name_hash_js_jsstore_dist_jsstore_worker_min_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(file_loader_name_scripts_name_hash_js_jsstore_dist_jsstore_worker_min_js__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var file_loader_name_scripts_name_hash_js_jsstore_dist_jsstore_worker_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(36);
/* harmony import */ var file_loader_name_scripts_name_hash_js_jsstore_dist_jsstore_worker_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(file_loader_name_scripts_name_hash_js_jsstore_dist_jsstore_worker_js__WEBPACK_IMPORTED_MODULE_1__);


var ServiceHelper = /** @class */ (function () {
function ServiceHelper() {
}
ServiceHelper.idbCon = new jsstore__WEBPACK_IMPORTED_MODULE_0__["Instance"](new Worker(file_loader_name_scripts_name_hash_js_jsstore_dist_jsstore_worker_min_js__WEBPACK_IMPORTED_MODULE_1__));
ServiceHelper.idbCon = new jsstore__WEBPACK_IMPORTED_MODULE_0__["Instance"](new Worker(file_loader_name_scripts_name_hash_js_jsstore_dist_jsstore_worker_js__WEBPACK_IMPORTED_MODULE_1__));
return ServiceHelper;
}());

window.con = ServiceHelper.idbCon;


/***/ }),
/* 35 */
/***/ (function(module, exports) {

/*!
* @license :jsstore - V2.1.2 - 09/06/2018
* @license :jsstore - V2.2.1 - 01/07/2018
* https://github.com/ujjwalguptaofficial/JsStore
* Copyright (c) 2018 @Ujjwal Gupta; Licensed MIT
*/
Expand Down Expand Up @@ -11931,6 +11933,20 @@ var Instance = /** @class */ (function (_super) {
query: null
});
};
/**
* execute the transaction
*
* @param {ITranscationQry} query
* @returns
* @memberof Instance
*/
Instance.prototype.transaction = function (query) {
query.logic = query.logic.toString();
return this.pushApi({
name: _enums__WEBPACK_IMPORTED_MODULE_0__["API"].Transaction,
query: query
});
};
return Instance;
}(_instance_helper__WEBPACK_IMPORTED_MODULE_1__["InstanceHelper"]));

Expand Down Expand Up @@ -11997,6 +12013,7 @@ var API;
API["ExportJson"] = "export_json";
API["ChangeLogStatus"] = "change_log_status";
API["Terminate"] = "terminate";
API["Transaction"] = "transaction";
})(API || (API = {}));


Expand Down Expand Up @@ -12292,7 +12309,7 @@ var Column = /** @class */ (function () {
/* 36 */
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__.p + "scripts/jsstore.worker.min.86e3c8e8ff529b5eaee0edee0e771a2b.js";
module.exports = __webpack_require__.p + "scripts/jsstore.worker.4048421cf4853f428aa9a85486d71967.js";

/***/ }),
/* 37 */
Expand Down Expand Up @@ -12692,27 +12709,22 @@ var QueryExecutor = /** @class */ (function (_super) {
QueryExecutor.prototype.evaluateAndShowResult = function (qry) {
var _this = this;
var queryHelperInstance = new _helpers_query_helper__WEBPACK_IMPORTED_MODULE_6__["QueryHelper"](qry);
if (queryHelperInstance.isQryValid()) {
var query = queryHelperInstance.getQuery();
if (queryHelperInstance.errMessage.length == 0) {
new _service_main_service__WEBPACK_IMPORTED_MODULE_5__["MainService"]()
.executeQry(query)
.then(function (qryResult) {
_this.showResultInfo = true;
_this.resultCount =
_util__WEBPACK_IMPORTED_MODULE_8__["Util"].getType(qryResult.result) === jsstore__WEBPACK_IMPORTED_MODULE_9__["DATA_TYPE"].Array
? qryResult.result.length
: 0;
_this.timeTaken = qryResult.timeTaken.toString();
_common_var__WEBPACK_IMPORTED_MODULE_2__["vueEvent"].$emit("on_qry_result", qryResult.result);
})
.catch(function (err) {
_common_var__WEBPACK_IMPORTED_MODULE_2__["vueEvent"].$emit("on_qry_error", err);
});
}
else {
_common_var__WEBPACK_IMPORTED_MODULE_2__["vueEvent"].$emit("on_error", queryHelperInstance.errMessage);
}
if (queryHelperInstance.validateAndModifyQry()) {
var query = queryHelperInstance.query;
new _service_main_service__WEBPACK_IMPORTED_MODULE_5__["MainService"]()
.executeQry(query)
.then(function (qryResult) {
_this.showResultInfo = true;
_this.resultCount =
_util__WEBPACK_IMPORTED_MODULE_8__["Util"].getType(qryResult.result) === jsstore__WEBPACK_IMPORTED_MODULE_9__["DATA_TYPE"].Array
? qryResult.result.length
: 0;
_this.timeTaken = qryResult.timeTaken.toString();
_common_var__WEBPACK_IMPORTED_MODULE_2__["vueEvent"].$emit("on_qry_result", qryResult.result);
})
.catch(function (err) {
_common_var__WEBPACK_IMPORTED_MODULE_2__["vueEvent"].$emit("on_qry_error", err);
});
}
else {
_common_var__WEBPACK_IMPORTED_MODULE_2__["vueEvent"].$emit("on_error", queryHelperInstance.errMessage);
Expand Down Expand Up @@ -13328,7 +13340,7 @@ var QueryHelper = /** @class */ (function () {
this.errMessage = "";
this.query = query;
}
QueryHelper.prototype.getQuery = function () {
QueryHelper.prototype.validateAndModifyQry = function () {
var _this = this;
var qry;
var isAnyApiFound = false;
Expand All @@ -13337,13 +13349,13 @@ var QueryHelper = /** @class */ (function () {
var index = _this.query.indexOf(api + "(");
if (index >= 0) {
isAnyApiFound = true;
_this.query = _this.query.substring(0, index) + "this.connection.\n " + _this.query.substring(index, _this.query.length);
_this.query = _this.query.substring(0, index) + "con.\n " + _this.query.substring(index, _this.query.length);
}
});
if (!isAnyApiFound) {
this.errMessage = "No valid api was found";
}
return this.query;
return !this.errMessage.length;
};
Object.defineProperty(QueryHelper.prototype, "allowedApi", {
get: function () {
Expand All @@ -13357,23 +13369,22 @@ var QueryHelper = /** @class */ (function () {
_enum__WEBPACK_IMPORTED_MODULE_0__["API"].Count,
_enum__WEBPACK_IMPORTED_MODULE_0__["API"].DropDb,
_enum__WEBPACK_IMPORTED_MODULE_0__["API"].BulkInsert,
_enum__WEBPACK_IMPORTED_MODULE_0__["API"].ExportJson
_enum__WEBPACK_IMPORTED_MODULE_0__["API"].ExportJson,
_enum__WEBPACK_IMPORTED_MODULE_0__["API"].Transaction
];
},
enumerable: true,
configurable: true
});
QueryHelper.prototype.isQryValid = function () {
var _this = this;
var notAllowedKeywords = ["Instance", "then", "catch"];
notAllowedKeywords.every(function (item) {
if (_this.query.indexOf(item) >= 0) {
_this.errMessage = "keyword: '" + item + "' is not allowed, only write code for api call";
return false;
}
QueryHelper.prototype.isQryValid_ = function () {
var fn = eval(this.query);
if (typeof fn.then === 'function') {
return true;
});
return !this.errMessage.length;
}
else {
this.errMessage = "The query should return a promise";
}
return false;
};
return QueryHelper;
}());
Expand Down Expand Up @@ -13407,6 +13418,7 @@ var API;
API["BulkInsert"] = "bulkInsert";
API["ExportJson"] = "exportJson";
API["ChangeLogStatus"] = "changeLogStatus";
API["Transaction"] = "transaction";
})(API || (API = {}));


Expand Down
2 changes: 1 addition & 1 deletion src/output/scripts/bundle.js.map

Large diffs are not rendered by default.

0 comments on commit ac89104

Please sign in to comment.