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']

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务