There is a Java paradigm for accessing a database implemented in Java DataSource. This object creates a useful abstraction around creating database connections. The object DataSourcesaves the database configuration, but upon request it will create connections to the database. This allows you to save the entire database configuration and initialization code in one place and simplify changing the database implementation or use the mock database for testing.
I am currently working on a Python project that uses cx_Oracle. In cx_Oracle, you get the connection directly from the module:
import cx_Oracle as dbapi
connection = dbapi.connect(connection_string)
I am trying to find a parallel with DataSourcein cx_Oracle. I can easily create this by creating a new class and wrapping cx_Oracle, but I was wondering if this was the right thing to do in Python.
source
share