Re: [SQLObject] Generic "find" & findOne method
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2004-12-29 16:58:48
|
Carlos Ribeiro wrote: > It turns out that Ian's time machine is almost as good as Guido's one. > There *is* a find() method on the current SQLObject; it's called > selectBy and it's not documented anywhere else. I only found it today > while looking for something else. BTW, I admit being ashamed about it > :-( > > Now, just out of curiosity: is selectBy undocumented just for lack of > time, or is it because it's not recommended? Forgetfulness. I've added a note to the svn docs. With reference to the rest of the discussion -- I don't like the findOne function, because it throws things away. I'd rather it raise an error when more than one record was found; I don't think there's a use case for throwing rows away, it's just easy to implement. In most cases alternateID fills the role of select-one, though another way of doing this might be useful. Actually, I think it's mostly useful because of the error issue. If you implement ad hoc findOne-like methods, you'll probably throw away extra columns. Maybe it could be a method for SelectResult methods, like: inst = MyTable.selectBy(...).getOne() But I don't like "getOne" as a method name. SQL injection won't be a problem, since we do all the necessary quoting -- that's part of the point of SQLObject and SQLBuilder, after all. You only have to be sure that all your columns are "public", more or less, since a person might be able to inject their own form variables. But it's also easy to test that your keys are limited to a specific set of columns. -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |