ujjwalguptaofficial / JsStore

Simplifying IndexedDB with SQL like syntax and promises
http://jsstore.net/
MIT License
858 stars 110 forks source link

Can't get like operator to work properly #82

Closed bdhaegar closed 5 years ago

bdhaegar commented 6 years ago

When I use the where clause the query result looks perfectly fine. When I use the like operator I do get duplicate objects per hit with the same exact data.

Any ideas? Here is the code that I am using.

var connection = new JsStore.Instance();

connection.openDb("MtnWestPublic");

connection.select({

from: "PipelineTable",

// This works and delivers one record //where: { // PipelineSegment: "43951-1", //}

//This does not work correctly and delivers multiple records (32) for each hit even though they are unique //43951-1,43951-1,.....,43951-2,43951-2,...... where: { PipelineSegment: { like: '43951%' }, }

}).then(function(results) { //results will be array of objects. console.log(results); b = JSON.stringify(results); localStorage.setItem("offlinePipelineSegmentQuery", b); }).catch(function(error) { alert(error.message); });

ujjwalguptaofficial commented 6 years ago

could you add "-" in like query and let me know what its returning ?

where: {
PipelineSegment: {
like: '43951-%'
},
bdhaegar commented 6 years ago

adding the "-" character did not help, but I think you pointed to the right spot.

I changed the query by using another field where no column entries with special characters do exist and it worked. Eventually the like function does not protect special characters?

Example that worked:

where: { CompanyName: { like: "NOVA%" } }

ujjwalguptaofficial commented 6 years ago

ok I see. I will look into this issue.

ujjwalguptaofficial commented 5 years ago

Just for the documentation - the like query with format - "value%" was using indexeddb query - var range = IDBKeyRange.bound("BA", "BA" + '\uffff');. This makes it more faster.

since its does not work for special characters, I have removed this and updated the code to work as other like query.

ujjwalguptaofficial commented 5 years ago

@bdhaegar - I have solved this issue and published new version 2.8.2 . Please download this version and let me know if your issue is resolved.

Thanks