robert-j
(Robert J)
1
When isUpsert is set to true, when updating a object the “updated” timestamp is 01/19/1970 20:13:10
When set to false, the decision tree goes on to look for a objectID and decides to update or create.
So what is the use case for ever setting isUpsert to true?
public func save(entity: Any, isUpsert: Bool, responseHandler: ((Any) -> Void)!, errorHandler: ((Fault) -> Void)!) {
if isUpsert,
let entityDictionary = PersistenceHelper.shared.entityToSimpleType(entity: entity) as? [String : Any] {
persistenceServiceUtils.upsert(entity: entityDictionary, responseHandler: wrapResponse(responseHandler), errorHandler: errorHandler)
}
else if let entityDictionary = PersistenceHelper.shared.entityToSimpleType(entity: entity) as? [String : Any] {
if PersistenceHelper.shared.getObjectId(entity: entity) != nil {
persistenceServiceUtils.update(entity: entityDictionary, responseHandler: wrapResponse(responseHandler), errorHandler: errorHandler)
}
else {
persistenceServiceUtils.create(entity: entityDictionary, responseHandler: wrapResponse(responseHandler), errorHandler: errorHandler)
}
}
}
Hello @robert-j,
The upsert operation is very similar to the save one but more complicated:
- If you save the object with objectId and upsert = true:
- if object with the same objectId exists in the database - it will be updated
- if not - a new object with specified objectId will be created
- If you save the object without objectId and upsert = true:
- a new object with autogenerated objectId will be created
The upsert and bulk upset operations are not supported for the “DeviceRegistration” table.
Regards,
Olha
robert-j
(Robert J)
3
If the isUpsert is set to false it follows the same logic though, no?
Looks like its a server side issue with the “updated” time getting set to 0 when using isUpsert
Robert
- If
upsert
is set to false and you’re trying to create a new object with specified objectId
, e.g.
let testObject = ["objectId": "testId"]
you’ll receive the Entity with ID testId not found
error.
- If
upsert
is set to true and you’re trying to create a new object with specified objectId
, a new object will be created.
- For update logic yes, it works very similar.
According to the updated value issue - please provide steps and values you use, because I cannot reproduce it.
robert-j
(Robert J)
5
Ok I understand now.
Here is a test project, when you run it you can see the updated timestamp in console.
test-CRUD.zip (467.6 KB)
Hello Robert,
I was able to reproduce this issue not only in Swift-SDK. The internal ticket BKNDLSS-27915 is created for our backend developer.
Hello @robert-j
We’ve just updated cloud servers with a fix for the issue you described above. Could you kindly let us know whether fix works for you well?
Regards,
Inna