Skip to content

Commit 2ce1f1d

Browse files
committed
Add example for cx_Oracle SessionPool use
Change-Id: I88fe16764922ac567a89b8ac2c87402b9b693de9
1 parent 930e1a8 commit 2ce1f1d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/sqlalchemy/dialects/oracle/cx_oracle.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@
9393
9494
* ``encoding_errors`` - see :ref:`cx_oracle_unicode_encoding_errors` for detail.
9595
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+
96125
97126
.. _cx_oracle_unicode:
98127

0 commit comments

Comments
 (0)