Hi folks, I was wondering how people deal with D1 not supporting transactions on the client side whe
Hi folks,
I was wondering how people deal with D1 not supporting transactions on the client side when an insert of a child table needs to have the id of the parent (ie insert parent, insert many children with parent_id, or rollback)
I am thinking of 2 options:
Have an "is_orphan" column on the parent, commit, insert children and set false in a batch, and have a cleanup process scheduled for is_orphan = true.
Or have a separate "sequence" table, where the first commit monotonically increments, and then insert parent with id provided, insert children in a batch. That way though ids could exhaust if there is a bug on the client (ie getting new ids, crashing in batch)
Is there any other option?
I was wondering how people deal with D1 not supporting transactions on the client side when an insert of a child table needs to have the id of the parent (ie insert parent, insert many children with parent_id, or rollback)
I am thinking of 2 options:
Have an "is_orphan" column on the parent, commit, insert children and set false in a batch, and have a cleanup process scheduled for is_orphan = true.
Or have a separate "sequence" table, where the first commit monotonically increments, and then insert parent with id provided, insert children in a batch. That way though ids could exhaust if there is a bug on the client (ie getting new ids, crashing in batch)
Is there any other option?




