Preliminary refactors.

* Fix imports.
* Make lock and logger private attributes.
Setup a context manager for queries.

* Move type registration at initializer.
* Factor a `login` function out of `_connectToDb`.
* Guarantee lock is acquired and released.
* Guarantee connection is opened and closed.
Execute queries inside the context manager.
Drop old connect/disconnect utilities.