# Path: django_prometheus/db/common.py
# class DatabaseWrapperMixin:
#     """Extends the DatabaseWrapper to count connections and cursors."""
# 
#     def get_new_connection(self, *args, **kwargs):
#         connections_total.labels(self.alias, self.vendor).inc()
#         try:
#             return super().get_new_connection(*args, **kwargs)
#         except Exception:
#             connection_errors_total.labels(self.alias, self.vendor).inc()
#             raise
# 
#     def create_cursor(self, name=None):
#         return self.connection.cursor(
#             factory=ExportingCursorWrapper(self.CURSOR_CLASS, self.alias, self.vendor)
#         )
# 
# def ExportingCursorWrapper(cursor_class, alias, vendor):
#     """Returns a CursorWrapper class that knows its database's alias and
#     vendor name.
#     """
# 
#     labels = {"alias": alias, "vendor": vendor}
# 
#     class CursorWrapper(cursor_class):
#         """Extends the base CursorWrapper to count events."""
# 
#         def execute(self, *args, **kwargs):
#             execute_total.labels(alias, vendor).inc()
#             with query_duration_seconds.labels(**labels).time(), (
#                 ExceptionCounterByType(errors_total, extra_labels=labels)
#             ):
#                 return super().execute(*args, **kwargs)
# 
#         def executemany(self, query, param_list, *args, **kwargs):
#             execute_total.labels(alias, vendor).inc(len(param_list))
#             execute_many_total.labels(alias, vendor).inc(len(param_list))
#             with query_duration_seconds.labels(**labels).time(), (
#                 ExceptionCounterByType(errors_total, extra_labels=labels)
#             ):
#                 return super().executemany(query, param_list, *args, **kwargs)
# 
#     return CursorWrapper


import psycopg2.extensions
from django.contrib.gis.db.backends.postgis import base
from django_prometheus.db.common import DatabaseWrapperMixin, ExportingCursorWrapper



class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
    def get_connection_params(self):
        conn_params = super().get_connection_params()

# Path: django_prometheus/db/common.py
# class DatabaseWrapperMixin:
#     """Extends the DatabaseWrapper to count connections and cursors."""
# 
#     def get_new_connection(self, *args, **kwargs):
#         connections_total.labels(self.alias, self.vendor).inc()
#         try:
#             return super().get_new_connection(*args, **kwargs)
#         except Exception:
#             connection_errors_total.labels(self.alias, self.vendor).inc()
#             raise
# 
#     def create_cursor(self, name=None):
#         return self.connection.cursor(
#             factory=ExportingCursorWrapper(self.CURSOR_CLASS, self.alias, self.vendor)
#         )
# 
# def ExportingCursorWrapper(cursor_class, alias, vendor):
#     """Returns a CursorWrapper class that knows its database's alias and
#     vendor name.
#     """
# 
#     labels = {"alias": alias, "vendor": vendor}
# 
#     class CursorWrapper(cursor_class):
#         """Extends the base CursorWrapper to count events."""
# 
#         def execute(self, *args, **kwargs):
#             execute_total.labels(alias, vendor).inc()
#             with query_duration_seconds.labels(**labels).time(), (
#                 ExceptionCounterByType(errors_total, extra_labels=labels)
#             ):
#                 return super().execute(*args, **kwargs)
# 
#         def executemany(self, query, param_list, *args, **kwargs):
#             execute_total.labels(alias, vendor).inc(len(param_list))
#             execute_many_total.labels(alias, vendor).inc(len(param_list))
#             with query_duration_seconds.labels(**labels).time(), (
#                 ExceptionCounterByType(errors_total, extra_labels=labels)
#             ):
#                 return super().executemany(query, param_list, *args, **kwargs)
# 
#     return CursorWrapper


# Path: django_prometheus/db/backends/postgis/base.py
import psycopg2.extensions
from django.contrib.gis.db.backends.postgis import base
from django_prometheus.db.common import DatabaseWrapperMixin, ExportingCursorWrapper




class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
    def get_connection_params(self):
        conn_params = super().get_connection_params()

        conn_params["cursor_factory"] = ExportingCursorWrapper(