[SQLObject] Generic "find" & findOne method
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Carlos R. <car...@gm...> - 2004-12-21 16:43:40
|
Hi, I'm writing a class method that finds a row in a table using arbitrary column names & values, as in: person.find({'name':'...', 'address':'...'}) find works like a select, but it takes a dictionary with column names and desired values. It search for records by AND'ing all clauses, and returns a list of rows. person.findOne({'name':'...', 'address':'...'}) findOne returns a single record. It raises an exception if no item is found. If more than one item is found, it returns the first one, and no exception is rased. The goal here is not efficiency, but flexibility. When writing code for web applications it's useful to have this generic query feature, and these methods are more convenient than building a select on the fly. If this code is useful, I can contribute a patch back to SQLObject. It involves simple modifications on dbconnection.py and main.py. -- Carlos Ribeiro Consultoria em Projetos blog: http://rascunhosrotos.blogspot.com blog: http://pythonnotes.blogspot.com mail: car...@gm... mail: car...@ya... |