On Tue, Mar 2, 2010 at 4:08 PM, L.Guruprasad <[email protected]> wrote:
> Hi all,
> I am new to using ORM and hence Storm as well. Here is my question.
>
> I have an object of a class A, named a1.
> I want to insert a1 into the database if there isn't already another
> record with the primary key value of a1.
> If there is a record already there, I want to update the record. How to
> go about doing this?

Assuming that you've got the Storm class defined something like:

    class A(object):
        __storm_table__ = 'a'
        id = Int(primary=True)
        ...

You should be able to do something like:

    obj = store.get(A, pk)
    if obj is None:
        obj = A()
        obj.id = pk
        store.add(obj)
    # update other columns here.
    store.commit()

This should result in a SELECT query followed by either an INSERT or UPDATE.

James.

-- 
storm mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/storm

Reply via email to