B. Database APIs

The mysql, oracleand postgresqlservices exist to merely import their pylib counterparts (MySQL, Oracle and PostgreSql respectively). The services themselves provide no api, they just provide configuration options to setup the connection caches that the pylib modules hold.

The APIs to the modules are essentially identical. There is really only one function of interest (though some contain other function which you should NOT rely on to exist in future releases), and that is getConnection. This function takes a connection name (as defined in the sw.conf file) and returns the connection associated with it. The connections are lazily made, i.e. they are not created when the SkunkWeb child process starts, but when the first call of getConnection with the connection name is made in a process.

Here's an example of typical usage using PostgreSQL:

import PostgreSql
db = PostgreSql.getConnection('test') # <--- as defined in sw.conf
cur = db.cursor()
cur.execute('select * from testTable')
result=cur.fetchall()
cur.close()