-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
I have an atomic transaction that is failing, and I'm trying to figure out why. My first step was to try understanding what's the exact data that I'm trying to commit. There isn't a single place where I can add a console.log
, but I have to manually log all the variables that I'm using to build my transaction.
To add such logging, I have to modify my transaction:
const res = await kv
.atomic()
.check({ key: ["companies", data.companyId], versionstamp: companyStamp })
.check({
key: ["stations", data.departureStationId],
versionstamp: departureStationStamp,
})
.check({
key: ["stations", data.arrivalStationId],
versionstamp: arrivalStationStamp,
})
.check({ key: ["trips", trip.id], versionstamp: tripStamp })
.set(["trips", trip.id], serializeTripTime(trip))
.commit();
+ const serializedTrip = serializeTripTime(trip)
+ console.log({
+ companyId: data.companyId,
+ companyStamp,
+ departureStationId: data.departureStationId,
+ departureStationStamp,
+ arrivalStationId: data.arrivalStationId,
+ arrivalStationStamp,
+ tripId: trip.id,
+ tripStamp: tripStamp,
+ serializedTrip,
+ });
const res = await kv
.atomic()
.check({ key: ["companies", data.companyId], versionstamp: companyStamp })
.check({
key: ["stations", data.departureStationId],
versionstamp: departureStationStamp,
})
.check({
key: ["stations", data.arrivalStationId],
versionstamp: arrivalStationStamp,
})
.check({ key: ["trips", trip.id], versionstamp: tripStamp })
- .set(["trips", trip.id], serializeTripTime(trip))
+ .set(["trips", trip.id], serializedTrip)
.commit();
It would be great if instead I could log the AtomicOperation
object, and get some sort of string serialization. Effectively, it means that my code change is reduced to
- const res = await kv
+ const transaction = kv
.atomic()
.check({ key: ["companies", data.companyId], versionstamp: companyStamp })
.check({
key: ["stations", data.departureStationId],
versionstamp: departureStationStamp,
})
.check({
key: ["stations", data.arrivalStationId],
versionstamp: arrivalStationStamp,
})
.check({ key: ["trips", trip.id], versionstamp: tripStamp })
.set(["trips", trip.id], serializeTripTime(trip))
+ console.log(transaction);
+ await transaction
.commit();
The current logged output is just AtomicOperation {}
, but something like this would be much more helpful:
AtomicOperation
check({ key: ["companies", "aaaa"], versionstamp: 1111 })
check({ key: ["stations", "bbbb"], versionstamp: 2222 })
check({ key: ["stations", "cccc"], versionstamp: 3333 })
check({ key: ["trips", "dddd"], versionstamp: 4444 })
set(["trips", "dddd"], { x: 2 })
(and it would be even better if I could just add a .log()
before .commit()
, rather than having to manually split my statement in three)