RJ
RJ6mo ago

`db.patch` accepts optional `_id` and `_creationTime` parameters

Is this expected?
4 Replies
erquhart
erquhart6mo ago
do they actually change if you patch them or is it just types (no bueno either way i'm guessing)
lee
lee6mo ago
I think it's to support cases like
const {foo, ...doc} = await db.get(id);
doc.bar = "hi";
// field foo doesn't change, bar changes
await db.patch(id, doc);
const {foo, ...doc} = await db.get(id);
doc.bar = "hi";
// field foo doesn't change, bar changes
await db.patch(id, doc);
The behavior i believe is that _id and _creationTime are allowed but throw an error if they don't match the existing one
RJ
RJOP6mo ago
I haven't tested extensively but I think just the types. That makes sense, although I'd expect db.replace to be intended for that use case, right? Either way if it's expected/desired that sounds good, I just noticed it while testing my confect version of the same, and wanted to understand the situation
lee
lee6mo ago
I agree it's a bit odd to use patch like this, yeah