Python REST - Inventory Management in Database?

Backendless Version (REST API ver?)

Client SDK (Python (REST))

Application ID : FF55A111-06AF-7EB1-FFDE-B5B62760CA00

Expected Behavior ???

Actual Behavior

  1. call my python write_database_object() function
  2. JSON response of write_database_object response = {‘code’: 1364, ‘message’: “Field ‘itemID’ doesn’t have a default value”, ‘errorData’: {}}
    ___operation=JSON_SET

MY QUESTION IS:

How should I be structuring an users Item Inventory and updating the amounts and itemIDs??? (as u can see i was looking at JSON_SET but i failed due to resolve the error code above.)

(basically i need one call to update a whole obj, but most times only one entry inside that)

Also, I was thinking transactions might be an idea for item updates…
but then i’m also thinking of frequency of updates… :confused:

Reproducible Test Case: (PYTHON)


backendless = PyBackendless.Backendless(APP_ID, REST_KEY)
#ITEMS = ItemsClass_BOUNCY_OC.ITEMS()#ITEMS IDs as VARIABLES
#THE FOLLOWING USER CAN BE USED WITHOUT hmac
data = {}
data["login"] = "NOhmacPW"
data["password"] = "12345"
response = backendless.login_user(data)
#backendless.initialize_user(response) #inside login_user
print(backendless.objectId)
tableName = "ItemInventory"
invJSONupdata = {
  "JSONinv":{
    "___operation":"JSON_SET",
    "args":{
      "$.slot0.itemID":0,
      "$.slot0.amt":1000000,
      "$.slot1.itemID":1,
      "$.slot1.amt":111,
      "$.slot2.itemID":2,
      "$.slot2.amt":11,
      "$.slot3.itemID":3,
      "$.slot3.amt":10,
      "$.slot4.itemID":4,
      "$.slot4.amt":100
    }
  }
}


where = "ownerId = '"+str(backendless.objectId)+"'" #WHERE: owner == user && itemID == itemID
response_containing_one_or_more = backendless.read_database_object(tableName,"JSONinv",where) #Returns
print("response_containing_one_or_more=",response_containing_one_or_more)
objectId = ""
if isinstance(response_containing_one_or_more, dict):
    already_have = True
    objectId = response_containing_one_or_more["objectId"]

response = backendless.update_database_object(tableName,invJSONupdata,objectId)
print("___operation=JSON_SET")
print(response)

RESPONDS WITH:
{‘code’: 1364, ‘message’: “Field ‘itemID’ doesn’t have a default value”, ‘errorData’: {}}

NEED HELP PLEASE…

Mainly I need know how I should be structuring a users Item Inventory and updating their Item amounts and itemIDs ???
Also… I’m not rich, so if there’s a cost effective way to do it, that’d be great…

EDIT:

really need it to be able to handle thousands of concurrent users too…

Thanks, Jessie.

Hello, @JesterOC.

For this task, to update information in real time, RT would be suitable.
You can check out the possibilities here:
https://backendless.com/docs/js/rt_updated_event_overview.html
But as far as I know, we don’t have a sdk for python at the moment. So you will have to implement it yourself.

Best Regards, Nikita.

I’d love to just " implement it myself ".

But it’s not my API… How would I even develop someone else’s API so i could?

I don’t understand.

My application is PC/Android… Sdk options are available, but i need something that works for BOTH PC/Android…

How to build backendless RT sdk for Python?

Currently, I’m savin the whole inventory as TEXT…
like so:

{ "m_slotCount": 10.0, "m_itemSlots": [ { "m_count": 500.0, "m_itemID": 0.0 }, { "m_count": 258.0, "m_itemID": 11.0 }, { "m_count": 300.0, "m_itemID": 13.0 }, { "m_count": 256.0, "m_itemID": 12.0 }, { "m_count": 150.0, "m_itemID": 14.0 }, { "m_count": 15.0, "m_itemID": 16.0 }, { "m_count": 1.0, "m_itemID": 48.0 }, { "m_count": 14.0, "m_itemID": 50.0 }, { "m_count": 15.0, "m_itemID": 48 }, { "m_count": 6.0, "m_itemID": 48 }, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 ], "m_slotMax": 54.0, "m_isContainer": false }

It’s a large string imo, BEING THE WHOLE INVENTORY… (thinking i’ll just save when necessary)
That being said it’s still alot quicker than doing individual calls for each item…
(the way i was doing before)…

Let me know if I’m doin it wrong…

The questions I’d ask are:

  • Do you need to retrieve the data from your inventory with queries? For instance, load all items where m_count > X ?
  • Do you need to update or delete individual items in the inventory?

If the answer is yes, then storing the inventory as a single JSON is not the simplest way to do it and it warrants creating individual database records for the individual inventory items.

Do you need to retrieve the data from your inventory with queries? For instance, load all items where m_count > X ?

no, i can do that on client…

Do you need to update or delete individual items in the inventory?

Yes, but no, its not necessary, i can do it on the client then just send the whole inventory… (It’s likely quicker overall)

I did have it updating individual database records for the individual inventory items, but it took ages… Prolly cus it waits for the response each time… And to update you require objectId, which requires you to have already read.

Short answer… No.
I can probabublly just be okay with TEXT type and full inventory updates. :smiling_face:

I just need to be careful about how often the inventory updates are…

Thanks :+1::blush: