Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg_readonly: psycopg3 support #55

Open
Tracked by #46
m1kc opened this issue May 15, 2023 · 0 comments
Open
Tracked by #46

pg_readonly: psycopg3 support #55

m1kc opened this issue May 15, 2023 · 0 comments
Labels
feature New feature or request

Comments

@m1kc
Copy link
Owner

m1kc commented May 15, 2023

from django.db.backends.postgresql import base
class DatabaseWrapper(base.DatabaseWrapper):
	def get_new_connection(self, conn_params):
		conn = super(DatabaseWrapper, self).get_new_connection(conn_params)
		if hasattr(conn, 'read_only'):
			# pyscopg3
			conn.read_only = True
		elif hasattr(conn, 'set_session'):
			# pyscopg2
			conn.set_session(readonly=True)
		else:
			raise RuntimeError("pg_readonly: unknown adapter type (only pyscopg2 and pyscopg3 are supported)")
		return conn
@m1kc m1kc added the feature New feature or request label May 15, 2023
@m1kc m1kc mentioned this issue May 15, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant