Can someone explain what psycopg2's connection_factory is and how to use it?
I've been looking at a project's code that connects to postgres via the connection_factory and I am at a lost. I have looked at the docs, https://www.psycopg.org/docs/module.html, but all it tells me is:
Using the connection_factory parameter a different class or connections factory can be specified. It should be a callable object taking a dsn string argument.
Looking at the cursor factories
and connection
becomes overwhelming and I don't even know if it is still related to the connection_factory
.
Below is the code that I am looking at:
class PsycoConnection(psycopg2.extensions.connection):
def lobject(*args, **kwargs):
pass
Somewhere in another class the above class gets called as follows:
result = psycopg2.connect(
connection_factory=PsycoConnection,
**connection_info)
Normally when I use psycopg2 to connect to a database I simple do something like below:
result = psycopg2.connect("host=127.0.0.1 port=5433 dbname=yugabyte sslmode=prefer")
I know the connection_info
is not any different to "host=127.0.0.1 port=5433 dbname=yugabyte sslmode=prefer"
except it's a dict. So my question is what is this PsycoConnection
passed to connection_factory
? To me the PsycoConnection
class isn't even doing anything since the only code is pass
. Thank you.