File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
lib/sqlalchemy/dialects/oracle Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 93
93
94
94
* ``encoding_errors`` - see :ref:`cx_oracle_unicode_encoding_errors` for detail.
95
95
96
+ .. _cx_oracle_sessionpool:
97
+
98
+ Using cx_Oracle SessionPool
99
+ ---------------------------
100
+
101
+ The cx_Oracle library provides its own connectivity services that may be
102
+ used in place of SQLAlchemy's pooling functionality. This can be achieved
103
+ by using the :paramref:`_sa.create_engine.creator` parameter to provide a
104
+ function that returns a new connection, along with setting
105
+ :paramref:`_sa.create_engine.pool_class` to ``NullPool`` to disable
106
+ SQLAlchemy's pooling::
107
+
108
+ import cx_Oracle
109
+ from sqlalchemy import create_engine
110
+ from sqlalchemy.pool import NullPool
111
+
112
+ pool = cx_Oracle.SessionPool(
113
+ user="scott", password="tiger", dsn="oracle1120",
114
+ min=2, max=5, increment=1, threaded=True
115
+ )
116
+
117
+ engine = create_engine("oracle://", creator=pool.acquire, poolclass=NullPool)
118
+
119
+ The above engine may then be used normally where cx_Oracle's pool handles
120
+ connection pooling::
121
+
122
+ with engine.connect() as conn:
123
+ print(conn.scalar("select 1 FROM dual"))
124
+
96
125
97
126
.. _cx_oracle_unicode:
98
127
You can’t perform that action at this time.
0 commit comments