This module is a very simple module. The source code is the following:
import MySQLdb ################ CherryClass MySql abstract: ################ function: def openConnection(self, host, user, passwd, db): self.connection=MySQLdb.connect(host, user, passwd, db) def query(self, query): c=self.connection.cursor() c.execute(query) res=c.fetchall() c.close() return res
All it does is it provides a CherryClass wrapper to the Python MySQLdb module
All you have to do to use it is declare a CherryClass that inherits from MySql, call the openConnection method in the __init__ method, and use query to execute a query and get the result.
The connection will be automatically opened when the server gets started (when your CherryClass gets instantiated), and it will remain open until the server dies.
The following code is an example on how to use the module:
use MySql CherryClass MyDb(MySql): function: def __init__(self): self.openConnection('host', 'user', 'password', 'database') CherryClass Root: mask: def index(self): <html><body> Hello, there are currently <py-eval="myDb.query('select count(*) from user')[0][0]"> users in the database </body></html>