views:

26

answers:

1

i'm using elixir as my orm for mysql database, and it's hard for me to write a update sql under elixir

"update products set price=NULL where id>100"

class Product(Entity):
    using_options(tablename='model_product')
    name                        = Field(Unicode(200))
    en_name             = Field(Unicode(200))
    price                       = Field(Float)
    en_price            = Field(Float)
    productid                   = Field(Unicode(200))
    site                        = Field(Unicode(30))
    link                        = Field(Unicode(300))
    smallImage                  = Field(Unicode(300))
    bigImage                    = Field(Unicode(300))
    description                 = Field(UnicodeText)
    en_description              = Field(UnicodeText)
    createdOn                   = Field(DateTime, default=datetime.datetime.now)
    modifiedOn                  = Field(DateTime, default=datetime.datetime.now)
    size                        = Field(Unicode(30))
    en_size                     = Field(Unicode(30))
    weight                      = Field(Unicode(30))
    en_weight                   = Field(Unicode(30))
    wrap                        = Field(Unicode(30))
    en_wrap                     = Field(Unicode(30))
    material                    = Field(Unicode(30))
    en_material                 = Field(Unicode(30))
    packagingCount              = Field(Unicode(30))
    stock                       = Field(Integer)
    location                    = Field(Unicode(30))
    en_location                 = Field(Unicode(30))
    popularity                  = Field(Integer)
    inStock                     = Field(Boolean)
    categories                  = Field(Unicode(30))

anyone could give me some help

A: 

Try to think in terms of objects, not SQL, which is the reason for having an ORM.
I pretty much just followed the elixir tutorial with your class:

for p in Product.query.filter(Product.id > 100):
    p.price = None
session.commit()

In SQLAlchemy, Python's None maps to a NULL in SQL: Common Filter Operators

ma3
the performance is really bad
mlzboy