SQLAlchemy的封装:Elixir ORM
jopen
12年前
Elixir是基于python界有名的ORM库SQLAlchemy做的封装。而且是轻量级的封装,它提供了更简单的方式来创建Python类并直接映射到关系数据库表(即通常所说的Active Record设计模式),类似于Django中的ORM。
示例:
class Person(Entity): name = Field(String(128)) addresses = OneToMany('Address') class Address(Entity): email = Field(Unicode(128)) owner = ManyToOne('Person')
class Person(Entity): id = Field(Integer, primary_key=True) name = Field(String(50), required=True) ssn = Field(String(50), unique=True) biography = Field(Text) join_date = Field(DateTime, default=datetime.datetime.now) photo = Field(Binary, deferred=True) _email = Field(String(20), colname='email', synonym='email' class Admin( Party.Admin ): verbose_name = _( 'Person' ) list_display = ['first_name', 'last_name', 'contact_mechanisms_email', 'contact_mechanisms_phone']