ujjwalguptaofficial / JsStore

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

Simple way to increment a field? #29

Closed NJseo closed 6 years ago

NJseo commented 6 years ago

Is there a simple way to increment a filed or do I have to do a get than an update?

NJseo commented 6 years ago

So here is what I figured out. When I get an item to check if its in the database, on the initial, it returns results as a single object. After one item gets put into the database, it returns as an object inside of an array. I think this is a mistake. It should always return as an object in an array.

ujjwalguptaofficial commented 6 years ago

Lets first talk about this -

Is there a simple way to increment a filed or do I have to do a get than an update?

You can use column option AutoIncrement. or is there something else you want ?

NJseo commented 6 years ago

Seems like autoincrement would work out great.

NJseo commented 6 years ago

Oh, wait. This is not an auto incrementing field, say like an id. Its more like sql's 'hitsField' = 'hitsField' + 1

ujjwalguptaofficial commented 6 years ago

yes, so do you want anything else ?

Basically autoincrement means - the field which is marked autoincrement will be incremented automatically, you don't need to suppy value for that field.

NJseo commented 6 years ago

Yeah, the url to that. Additionally, that update item function you provided me has been troublesome. I am passing it a json object and putting that to Set.

So it would be:

Set: [jsonValues], OnSuccess: function(rowsUpdated) { alert("updated fields"); },

Where the JSON object is: {id: "8787890780978907909", url: "https://www.smartychat.co", refferer: "https://www.google.com", bID: "thisID_780978907909", otherID: "780978907909", …}

Anyhow I keep getting back this message and its been troubling me for a good portion of the day.

TypeError: Cannot read property '_columns' of undefined at Instance.Base.getColumnInfo (jsstore.js:1291) at Instance.Base._this.goToWhereLogic (jsstore.js:1249) at Instance.execute (jsstore.js:4250) at Main.update (jsstore.js:1719) at Main.executeLogic (jsstore.js:1657) at Main.checkConnectionAndExecuteLogic (jsstore.js:1609) at self.onmessage (jsstore.js:5369)

ujjwalguptaofficial commented 6 years ago

I think - you are doing it wrong.

First Set does not take an array, it takes only object. So you specify only that field in object, which you want to update.

image

Please have a look at docs once - http://jsstore.net/tutorial/update

Thanks

ujjwalguptaofficial commented 6 years ago

Do one thing - write sql query and try to convert in jsstore equivalent. And run that jsstore code. If that does not worked send me the sql query - I will give you equivalent query. That way you will be able to understand.

Thanks

NJseo commented 6 years ago

Thankyou, I appreciate it. You are right, its easier to think sql first, the conversion second.

NJseo commented 6 years ago

"INSERT INTO t1 (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1";

ujjwalguptaofficial commented 6 years ago

INSERT INTO t1 (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1

Do you want me to write jsstore query for this ?

ujjwalguptaofficial commented 6 years ago

Can we close this issue if all good ?

NJseo commented 6 years ago

Yes, thank you.