def body_management(): # scope = app - objects will belong to the app scope in this case, so they will be available to every user scope = ObjectScope.for_app(APP) # bucket / folder in which objects will be stored bucket = "messages" # type for our objects object_type = "application/json" data = {"title": "msg1", "thread_id": 3434, "read": True} object_id = object_client.create(scope, bucket, object_type, data) # start upload upload_id = object_client.start_upload(scope, bucket, object_id) data_type = "application/javascript" data_file = 'function sayHello(args) {return "Hello " + args.name + "!"}' # range stuff length = len(data_file) range_size = length // 4 start = 0 end = range_size - 1 # uploading while start < length - 1: chunk = data_file[start : end + 1] object_client.upload_chunk(scope, bucket, object_id, data_type, upload_id, chunk, start, end, length) start = end + 1 next = end + range_size end = next if next < length else length - 1 # commit upload object_client.commit_upload(scope, bucket, object_id, upload_id)
def object_management(): # scope = app - objects will belong to the app scope in this case, so they will be available to every user scope = ObjectScope.for_app(APP) # bucket / folder in which objects will be stored bucket = "messages" # type for our objects object_type = "application/json" data1 = {"title": "msg1", "thread_id": 3434, "read": True} data2 = {"title": "msg2", "thread_id": 3434, "read": True} data3 = {"title": "msg3", "thread_id": 3435, "read": False} object_id1 = object_client.create(scope, bucket, object_type, data1) object_id2 = object_client.create(scope, bucket, object_type, data2) object_id3 = object_client.create(scope, bucket, object_type, data3) # get read messages by thread q = BucketQuery.with_clause(C.cAnd(C.cEq("thread_id", 3434), C.cEq("read", True))).order_by("title", False) messages, paginationKey = object_client.query(scope, bucket, q) # mark read messages as unread for message in messages: unread = {"read": False} object_client.patch(scope, bucket, message["_id"], object_type, unread) # remove all messages q = BucketQuery.with_clause(C.cAll()) messages, paginationKey = object_client.query(scope, bucket, q) for message in messages: object_client.delete(scope, bucket, message["_id"])