美文网首页
SqlAlchemy操作手册

SqlAlchemy操作手册

作者: sa_justin | 来源:发表于2017-06-07 14:46 被阅读0次

    assuming certain column names...

    INSERT one

    newToner = Toner(toner_id = 1,

    toner_color = 'blue',

    toner_hex = '#0F85FF')

    dbsession.add(newToner)

    dbsession.flush()

    INSERT multiple

    newToner1 = Toner(toner_id = 1,

    toner_color = 'blue',

    toner_hex = '#0F85FF')

    newToner2 = Toner(toner_id = 2,

    toner_color = 'red',

    toner_hex = '#F01731')

    dbsession.add_all([newToner1, newToner2])

    dbsession.flush()

    UPDATE

    q = dbsession.query(Toner)

    q = q.filter(Toner.toner_id==1)

    record = q.one()

    record.toner_color = 'Azure Radiance'

    dbsession.flush()

    or using a fancy one-liner using MERGE

    record = dbsession.merge(Toner( **kwargs))

    相关文章

      网友评论

          本文标题:SqlAlchemy操作手册

          本文链接:https://www.haomeiwen.com/subject/euzofxtx.html