pkg/graphdb: use transactions for transactions

This PR is needed to get #9615 merged.