Add public API for pkgdb transactions.
Use transactions for pkg-set.

Speed up can reach 10 or even 100 times comparing to the naive version.