Skip to content

Commit

Permalink
delete multiple or and code added.
Browse files Browse the repository at this point in the history
V 1.4.0
  • Loading branch information
ujjwalguptaofficial committed Jan 6, 2018
1 parent 24d0421 commit f0d1acf
Show file tree
Hide file tree
Showing 18 changed files with 880 additions and 474 deletions.
98 changes: 64 additions & 34 deletions Code/JsStore/Business/Delete/InstanceLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,99 @@ namespace JsStore {
this._query = query;
this._onSuccess = onSuccess;
this._onError = onError;
this._transaction = db_connection.transaction([query.From], "readwrite");
this._objectStore = this._transaction.objectStore(query.From);
this._transaction.oncomplete = this.onTransactionCompleted.bind(this);
this._transaction.onerror = this.onErrorOccured.bind(this);

if (query.Where) {
if (query.Where.Or) {
this.executeOrLogic();
if (Array.isArray(query.Where)) {
this.processWhereArrayQry();
}
else {
this.processWhere(false);
}
this.goToWhereLogic();
}
else {
this.createTransaction();
this.executeWhereUndefinedLogic();
}

}
catch (ex) {
this._errorOccured = true;
this.onExceptionOccured(ex, { TableName: query.From });
}
}

private processWhereArrayQry = function () {
var select_object = new Select.Instance(this._query as any,
function (results) {
var key_list = [],
p_key = this.getPrimaryKey(this._query.From);
results.forEach(function (item) {
key_list.push(item[p_key]);
});
results = null;
this._query.Where = {};
this._query.Where[p_key] = { In: key_list };
this.processWhere(false);
}.bind(this), this._onError);
};

private processWhere = function (isTransactionCreated) {
if (this._query.Where.Or) {
this.processOrLogic();
this.createTransactionForOrLogic();
}
else if (isTransactionCreated === false) {
this.createTransaction();
}
this.goToWhereLogic();
};

private createTransaction = function () {
this._transaction = db_connection.transaction([this._query.From], "readwrite");
this._objectStore = this._transaction.objectStore(this._query.From);
this._transaction.oncomplete = this.onTransactionCompleted.bind(this);
this._transaction.onerror = this.onErrorOccured.bind(this);
};

private onTransactionCompleted = function () {
this._onSuccess(this._rowAffected);
};

private createtransactionForOrLogic = function (query) {
this._query = query;
private createTransactionForOrLogic = function () {
try {
this._transaction = db_connection.transaction([query.From], "readwrite");
this._transaction.oncomplete = this.onTransactionCompleted.bind(this);
this._transaction = db_connection.transaction([this._query.From], "readwrite");
this._transaction.oncomplete = this.orQuerySuccess.bind(this);
(this._transaction).ontimeout = this.onTransactionTimeout.bind(this);
this._objectStore = this._transaction.objectStore(query.From);
this.goToWhereLogic();
this._objectStore = this._transaction.objectStore(this._query.From);
}
catch (ex) {
this.onExceptionOccured(ex, { TableName: query.From });
this._errorOccured = true;
this.onExceptionOccured(ex, { TableName: this._query.From });
}
};

private orQuerySuccess = function () {
var key = getObjectFirstKey((this as any)._orInfo.OrQuery);
if (key != null) {
var where = {};
where[key] = (this as any)._orInfo.OrQuery[key];
delete (this as any)._orInfo.OrQuery[key];
this._query.Where = where;
this.createTransactionForOrLogic();
this.goToWhereLogic();
}
else {
(this as any)._orInfo.OnSucess(this._rowAffected);
}
};

private executeOrLogic = function () {
(this as any).OrInfo = {
private processOrLogic = function () {
(this as any)._orInfo = {
OrQuery: this._query.Where.Or,
OnSucess: this._onSuccess
};
(this as any).TmpQry = {
From: this._query.From,
Where: {}
} as ISelect;
var onSuccess = function () {
var key = getObjectFirstKey((this as any).OrInfo.OrQuery);
if (key != null) {
(this as any).TmpQry['Where'][key] = (this as any).OrInfo.OrQuery[key];
delete (this as any).OrInfo.OrQuery[key];
this.createtransactionForOrLogic((this as any).TmpQry);
delete (this as any).TmpQry['Where'][key];
}
else {
(this as any).OrInfo.OnSucess(this._rowAffected);
}
};

// free or memory
delete this._query.Where.Or;
this._onSuccess = onSuccess;
};
}
}
Expand Down
40 changes: 12 additions & 28 deletions Code/JsStore/Business/Update/InstanceLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,17 @@ namespace JsStore {
this.checkSchema(query.Set, query.In);
if (!this._errorOccured) {
this._query = query;
var createTransaction = function () {
this._transaction = db_connection.transaction([query.In], "readwrite");
this._objectStore = this._transaction.objectStore(query.In);
this._transaction.oncomplete = this.onTransactionCompleted.bind(this);
(this._transaction as any).ontimeout = this.onTransactionTimeout;
}.bind(this);

if (query.Where) {
if (query.Where.Or || Array.isArray(query.Where)) {
this.executeComplexLogic();
}
else {
createTransaction();
this.createTransaction();
this.goToWhereLogic();
}
}
else {
createTransaction();
this.createTransaction();
this.executeWhereUndefinedLogic();
}
}
Expand All @@ -41,23 +34,15 @@ namespace JsStore {
}
}

protected onTransactionCompleted = function () {
private onTransactionCompleted = function () {
this._onSuccess(this._rowAffected);
};

private createtransactionForOrLogic = function (query) {
this._query = query;
try {
this._transaction = db_connection.transaction([query.In], "readwrite");
this._transaction.oncomplete = this.onTransactionCompleted.bind(this);
this._transaction.ontimeout = this.onTransactionTimeout.bind(this);
this._objectStore = this._transaction.objectStore(query.In);
this.goToWhereLogic();
}
catch (ex) {
this._errorOccured = true;
this.onExceptionOccured.call(this, ex, { TableName: query.From });
}
private createTransaction = function () {
this._transaction = db_connection.transaction([this._query.In], "readwrite");
this._objectStore = this._transaction.objectStore(this._query.In);
this._transaction.oncomplete = this.onTransactionCompleted.bind(this);
(this._transaction as any).ontimeout = this.onTransactionTimeout;
};

private executeComplexLogic = function () {
Expand All @@ -71,12 +56,11 @@ namespace JsStore {
results.forEach(function (value) {
in_query.push(value[key]);
});
results = null;
where_qry[key] = { In: in_query };
this.createtransactionForOrLogic({
In: this._query.In,
Where: where_qry,
Set: this._query.Set
});
this._query['Where'] = where_qry;
this.createTransaction();
this.goToWhereLogic();
}.bind(this), this._onError.bind(this));
};

Expand Down
12 changes: 8 additions & 4 deletions Code/output/jsstore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,8 @@ declare namespace JsStore {
namespace Update {
class Instance extends Where {
constructor(query: IUpdate, onSuccess: () => void, onError: (err: IError) => void);
protected onTransactionCompleted: () => void;
private createtransactionForOrLogic;
private onTransactionCompleted;
private createTransaction;
private executeComplexLogic;
private checkSchema(suppliedValue, tableName);
}
Expand Down Expand Up @@ -865,9 +865,13 @@ declare namespace JsStore {
namespace Delete {
class Instance extends Where {
constructor(query: IDelete, onSuccess: (recordDeleted: number) => void, onError: (err: IError) => void);
private processWhereArrayQry;
private processWhere;
private createTransaction;
private onTransactionCompleted;
private createtransactionForOrLogic;
private executeOrLogic;
private createTransactionForOrLogic;
private orQuerySuccess;
private processOrLogic;
}
}
}
Expand Down
Loading

0 comments on commit f0d1acf

Please sign in to comment.