4 ms·
Ah, you're right. But it would be nice if they showed this in the Readme, along the "wrapped" examples. Actually, going the "db.Begin" way would be more consis
by akavel 12y ago
Ah, you're right. But it would be nice if they showed this in the Readme, along the "wrapped" examples.
Actually, going the "db.Begin" way would be more consistent with the rest of the standard library.
Most of the Go APIs go to great length to be "external" (i.e. iterator-like), e.g. bufio.Scanner, and (of special note in this case!) database/sql.Tx! It appears to me the "internal"/callback APIs are introduced in those places where there are really compelling reasons, which justify breaking the consistency: e.g. for filepath.Walk, there's recurrence, so it's mostly giving up to the obviously K.I.S.S. way; in sort.Search, the benefit is that callback allows to evade need for generics/reflection.
- skybrian 12y agoOn the other hand, the Go API for App Engine also uses a closure for a transaction: https://cloud.google.com/appengine/docs/go/datastore/transactions https://cloud.google.com/appengine/docs/go/datastore/transac...