lifted connection pooling code from database/sql