Skip to content

Commit

Permalink
upsert collection
Browse files Browse the repository at this point in the history
  • Loading branch information
gunplar committed Oct 29, 2024
1 parent 290c4fb commit d89fe0f
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import naksha.model.*
import naksha.model.Naksha.NakshaCompanion.VIRT_COLLECTIONS
import naksha.model.Naksha.NakshaCompanion.partitionNumber
import naksha.model.NakshaError.NakshaErrorCompanion.COLLECTION_NOT_FOUND
import naksha.model.NakshaError.NakshaErrorCompanion.CONFLICT
import naksha.model.NakshaError.NakshaErrorCompanion.MAP_NOT_FOUND
import naksha.model.NakshaError.NakshaErrorCompanion.UNSUPPORTED_OPERATION
import naksha.model.objects.NakshaCollection
Expand Down Expand Up @@ -186,10 +187,23 @@ class PgWriter(
CreateCollection(session).execute(mapOf(write), write)
)

WriteOp.UPSERT -> cachedTupleNumber(
write,
upsertCollection(mapOf(write), write)
)
WriteOp.UPSERT ->
if (write.id == null || previousMetadataProvider.get(
VIRT_COLLECTIONS,
write.id!!
) == null )
{
cachedTupleNumber(
write,
CreateCollection(session).execute(mapOf(write), write))
}
else {
val updatedTuple = UpdateCollection(session).execute(mapOf(write), write)
?:
return ErrorResponse(CONFLICT, "Collection does not exist but was processed for update during upserting: ${write.id}")
updatePrevTupleCache(updatedTuple)
cachedTupleNumber(write, updatedTuple)
}

WriteOp.UPDATE -> {
val updatedTuple = UpdateCollection(session).execute(mapOf(write), write)
Expand Down Expand Up @@ -320,8 +334,4 @@ class PgWriter(
)
return collection
}

internal fun upsertCollection(map: PgMap, write: WriteExt): Tuple {
TODO("Implement me")
}
}

0 comments on commit d89fe0f

Please sign in to comment.