It looks like the answer to my question is no.

Is there any add-on (Elixer or whatever) which has a shortcut method like
what I'm asking?


I did find that "insert_or_update" is not the solution.
I also found an appropriate, but longer way to read or create:

page = Session.query(Page).filter(Page.url == url, Page.body==body).first()

if not page:

  page = Page(url = url, body=body)

  session.save(page)


> If you know the primary key identifiers of the object, you may also use
> merge():

page = Page(<primary key identifiers>)

  persisted_page = Session.merge(page)


> the latter will do the same thing automatically as the former (SQLA does
> not use IntegrityErrors to query the database).


AJ ONeal

On Mon, Dec 28, 2009 at 9:40 PM, CoolAJ86 <coola...@gmail.com> wrote:

> If I have an object User in rails with attributes first, last, and
> password I can do something like this
>
> user = {:first => 'John', :last => 'Doe'} # a dict-like object
> user = Users.find_or_create(user)
>
> is there any such convenience method in sqlalchemy?
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com<sqlalchemy%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to