Skip to content

Commit ccae5ca

Browse files
committed
Expose PGconn* raw pointer on the connection as a PyCapsule
1 parent 6b6b1a6 commit ccae5ca

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

psycopg/connection_type.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,19 @@ psyco_conn_deferrable_set(connectionObject *self, PyObject *pyvalue)
822822
return 0;
823823
}
824824

825+
/* _raw_pgconn - expose PGconn* as a Python capsule */
826+
827+
#define psyco_conn__raw_pgconn_doc \
828+
"Return the internal PGconn* as a Python Capsule."
829+
830+
static PyObject *
831+
psyco_conn__raw_pgconn_get(connectionObject *self)
832+
{
833+
EXC_IF_CONN_CLOSED(self);
834+
835+
return PyCapsule_New(self->pgconn, "psycopg2.connection._raw_pgconn", NULL);
836+
}
837+
825838

826839
/* set_client_encoding method - set client encoding */
827840

@@ -1243,6 +1256,10 @@ static struct PyGetSetDef connectionObject_getsets[] = {
12431256
(getter)psyco_conn_deferrable_get,
12441257
(setter)psyco_conn_deferrable_set,
12451258
psyco_conn_deferrable_doc },
1259+
{ "_raw_pgconn",
1260+
(getter)psyco_conn__raw_pgconn_get,
1261+
NULL,
1262+
psyco_conn__raw_pgconn_doc },
12461263
{NULL}
12471264
};
12481265
#undef EXCEPTION_GETTER

0 commit comments

Comments
 (0)