AQuickTutorial » History » Revision 8
Revision 7 (Aurynn Shaw, 01/22/2009 09:10 AM) → Revision 8/10 (Aurynn Shaw, 01/22/2009 09:10 AM)
h1. = Simpycity in a Hurry = And what to expect when you use it. h2. == Setup == First, set up Simpycity: <pre> {{{ >>> from simpycity.core import Function >>> from simpycity import config >>> config.host = 'localhost' >>> config.port = 5432 >>> config.user = 'user' >>> config.password = 'password' >>> config.database = 'dbname' </pre> }}} Then, create some basic functions. <pre> {{{ >>> f = Function("get_row",['id']) >>> f_all = Function("get_rows") </pre> *f_all* }}} '''f_all''' maps to the stored procedure "get_rows", which takes no arguments. *f*, '''f''', on the other hand, maps to the stored procedure "get_row", which takes a single argument, which we've named id. To call f_all, it's a standard python function: <pre> {{{ >>> all_results = f_all() </pre> }}} For get_row, it's the same Python call semantics, both positional and keyword arguments being supported <pre> {{{ >>> result = f(1) # get id 1 >>> result = f(id=1) # also get id 1 </pre> }}} The results (look kind of like) a result set from psycopg2, and can be iterated over as per normal: <pre> {{{ >>> for row in all_result: ... # do row stuff </pre> }}} and in the case of a single result, you can also call .next() or .fetchone() and get the row object. <pre> {{{ >>> row = result.next() # or >>> row = result.fetchone() </pre> }}}