Initial commit

Porting all the code from Qiita and extending the tests.
I've changed `Exception` to `PostgresError` as we only care about the errors raised by postgres.