sqlalchemy lookup tables

前端 未结 3 1142
忘了有多久
忘了有多久 2021-01-07 13:47

Hi I have a table in 3NF form

ftype_table = Table(
    \'FTYPE\',
    Column(\'ftypeid\', Integer, primary_key=True),
    Column(\'typename\', String(50)),
          


        
3条回答
  •  花落未央
    2021-01-07 14:31

    the UniqueObject recipe is the standard answer here: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject . The idea is to override the creation of File using either __metaclass__.call() or File.__new__() to return the already-existing object, from the DB or from cache (the initial DB lookup, if the object isn't already present, is obviously unavoidable unless something constructed around MySQL's REPLACE is used).

    edit: since I've been working on the usage recipes, I've rewritten the unique object recipe to be more portable and updated for 0.5/0.6.

提交回复
热议问题