summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-02-24 10:57:35 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-02-24 10:57:35 -0500
commit2ce1f1d9a8011a4673428850f01b04196e070957 (patch)
treec72df2466c31209fe5110fd69496bb800509984c
parent930e1a89373ff3ee8c35b6696ed6d70502f03566 (diff)
downloadsqlalchemy-2ce1f1d9a8011a4673428850f01b04196e070957.tar.gz
Add example for cx_Oracle SessionPool use
Change-Id: I88fe16764922ac567a89b8ac2c87402b9b693de9
-rw-r--r--lib/sqlalchemy/dialects/oracle/cx_oracle.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py
index 5ac8a777c..38b92117b 100644
--- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py
+++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py
@@ -93,6 +93,35 @@ The parameters accepted by the cx_oracle dialect are as follows:
* ``encoding_errors`` - see :ref:`cx_oracle_unicode_encoding_errors` for detail.
+.. _cx_oracle_sessionpool:
+
+Using cx_Oracle SessionPool
+---------------------------
+
+The cx_Oracle library provides its own connectivity services that may be
+used in place of SQLAlchemy's pooling functionality. This can be achieved
+by using the :paramref:`_sa.create_engine.creator` parameter to provide a
+function that returns a new connection, along with setting
+:paramref:`_sa.create_engine.pool_class` to ``NullPool`` to disable
+SQLAlchemy's pooling::
+
+ import cx_Oracle
+ from sqlalchemy import create_engine
+ from sqlalchemy.pool import NullPool
+
+ pool = cx_Oracle.SessionPool(
+ user="scott", password="tiger", dsn="oracle1120",
+ min=2, max=5, increment=1, threaded=True
+ )
+
+ engine = create_engine("oracle://", creator=pool.acquire, poolclass=NullPool)
+
+The above engine may then be used normally where cx_Oracle's pool handles
+connection pooling::
+
+ with engine.connect() as conn:
+ print(conn.scalar("select 1 FROM dual"))
+
.. _cx_oracle_unicode: