The PEAK Developers' Center   AddingPsycopgSupport UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
The following 132 words could not be found in the dictionary of 50 words (including 50 LocalSpellingWords) and are highlighted below:
Change   Connection   Factory   Generic   If   It   Likewise   Ls   Luckily   Namespace   Navigator   Note   Now   Postgre   Postgres   Psycopg   Put   Pysco   Pyscopg   Python   Schemes   This   Types   Where   actually   ad   add   adding   addition   against   allows   already   alternative   an   and   appropriate   as   be   belong   but   called   can   care   class   classes   code   configuration   connection   database   db   default   do   drivers   env   environment   existing   fairly   file   following   for   from   get   good   handle   have   hoc   host   import   in   included   information   ini   initd   into   involves   is   it   library   like   module   most   my   mymodule   n2   naming   naturally   new   now   of   org   page   pass   peak   pgdb   place   psycopg   put   re   run   scheme   schemes   should   site   so   software   specific   statements   still   storage   straightforward   support   supported   takes   template   test   that   the   there   this   to   up   use   useful   user   using   values   we   which   work   would   you   your  

Clear message


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 [WWW]PyscoPG support to PEAK as an alternative to the default pgdb PostgreSQL module. This involves the following:

Luckily we can re-use the existing Postgres classes to do most of the work. Put the following code into mymodule.py:

    1 from peak.storage.SQL import GenericSQL_URL, PGSQLConnection
    2 
    3 class PsycopgURL(GenericSQL_URL):
    4     supportedSchemes = ('psycopg',)
    5     defaultFactory   = 'mymodule.PsycopgConnection'
    6 
    7 class PsycopgConnection(PGSQLConnection):
    8     DRIVER = 'psycopg'
    9 
   10     supportedTypes = (
   11         'NUMBER', 'LONGINTEGER', 'INTEGER', 'FLOAT', 'STRING', 'BOOLEAN',
   12         'DATETIME', 'TIME', 'DATE', 'INTERVAL', 'BINARY', 'ROWID'
   13     )

This takes care of the URL and Connection classes. Now for the URL scheme. Put the following in a file called my-peak.ini:

[peak.naming.schemes] 
psycopg = "mymodule:PsycopgURL" 

Now you can test it using PEAK's Namespace Navigator like so:

env PEAK_CONFIG=./my-peak.ini PYTHONPATH=. peak n2 psycopg:user:pass@host/db 

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.


PythonPowered
EditText of this page (last modified 2004-04-16 18:47:34)
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck