Custom Database Connector Based on psycopg2 for External Postgres DB

31 views
Skip to first unread message

Brandon

unread,
Jun 9, 2016, 7:59:34 AM6/9/16
to Django users
Hi! I am attempting to create my own database connector for Django for an external PostgreSQL DB that I have running. For this application, I issue the SQL queries and get responses over a REST API, so in theory, I'd like to adopt what already exists in the Postgres connector (django.db.backends.postgresql_psycopg2 I believe). Ideally, my hope is that I'd just override the psycopg2 call to the Postgres DB with my own call to my REST API, since the SQL query is the same. But I'm having trouble figuring out where this can go and if it can be this simple. Any help or advice would be much appreciated, thanks in advance!

Michal Petrucha

unread,
Jun 9, 2016, 5:31:01 PM6/9/16
to django...@googlegroups.com
Hi Brandon,

In order for this to work, you'd need to reimplement a Python
DBAPI-compatible wrapper around your REST API with support for a bunch
of non-trivial features, such as correct parameter substitution, or
type handling. Also, you'd probably need to implement transaction
handling somehow, which will be a non-trivial thing, because
transactions by definition rely on some state of a database
connection, whereas REST is supposed to be stateless.

Overall, this does not sound like a good idea to me, and I would
strongly recommend using a regular Postgres database connection
instead.

Cheers,

Michal
signature.asc
Reply all
Reply to author
Forward
0 new messages