Note that this code is now included in PEAK, but the page is still useful as a template for adding support for new database drivers.
------------------------------------------------------------------------------
It is fairly straightforward to add pgdb
PostgreSQL module. This involves the following:
adding a class to handle Pyscopg URLs
adding a class to handle the database connection
adding a 'psycopg' URL scheme to PEAK's configuration
Luckily we can re-use the existing Postgres classes to do most of the work. Put the following code into mymodule.py
:
This takes care of the URL and Connection classes. Now for the URL scheme. Put the following in a file called my-peak.ini
:
Now you can test it using PEAK's Namespace Navigator like so:
Change user
, pass
, host
, and db
to appropriate values and you should get an environment which allows you to run ad-hoc SQL statements against your database.
Where you actually put the classes and configuration information is up to you. If you already have a site-specific library of Python code, the classes would naturally belong there. Likewise for the addition to peak.naming.schemes
: a site-specific peak.ini file would be a good place for this.