class Foo(Base): DB_TABLE = 'foos' c1 = INT() c2 = BOOL() c3 = DATE() c4 = DATETIME() c5 = VARCHAR() c6 = VARCHAR(null=True, blank=False) c7 = TEXT(null=True, validate=dict(re=r'\Ax')) c8 = BLOB(null=True)
class Foo(Base): DB_TABLE = 'foos' abc = INT( choices=XEnum( qw('value label title'), A=(1, 'AA', 'aaa'), B=(2, 'BB', 'bbb'), C=(4, 'CC', 'ccc'), ), multiple=True, default=3, null=True, ) efg = INT(choices={ 1: 'ONE', 2: 'TWO', 4: 'FOUR' }, multiple=True, default=2, null=True) xyz = VARCHAR(choices=XEnum(X='x', Y='y', Z='z'), default='x', null=True) flag = BOOL(choices={ True: 'ON', False: 'OFF' }, default=True, null=True)
class Baz(Base): DB_TABLE = 'bazs' id = INT(primary_key=True) bar_id = BELONGS_TO(Bar) baz = VARCHAR() is_last = BOOL()
class Bar(Base): DB_TABLE = 'bars' id = INT(primary_key=True) foo_id = BELONGS_TO(Foo) bar = VARCHAR() bazs = HasMany('Baz', 'bar_id', order_by='id') bar2 = HasOne('Bar2') last_baz = HasOne('Baz', lambda q, r: q.where(bar_id=r.id, is_last=True))
class Bar(Base): DB_INDEXES = ( dict(prefix='UNIQUE', on=('foo_id', 'rad')), ) DB_TABLE = 'bars' id = INT(auto_increment=True, primary_key=True) foo_id = BELONGS_TO(Foo) created_by = BELONGS_TO(User) created_at = DATETIME(default=NOW) updated_by = BELONGS_TO(User) updated_at = DATETIME(default=NOW) lock_version = INT(default=1) name = VARCHAR(default='?', unique=True, blank=False) chks = INT(choices=XEnum(A=1, B=2, C=4), multiple=True) rad = BOOL(choices={True: 'ON', False: 'OFF'})
class StrPk(Base): DB_TABLE = 'str_pks' id = VARCHAR(primary_key=True)
class Foo(Base): DB_TABLE = 'foos' id = INT(auto_increment=True, primary_key=True) name = VARCHAR()
class Foo(Base): DB_TABLE = 'foos' id = INT(primary_key=True) foo = VARCHAR() bars = HasMany('Bar', order_by=('id', ))
class Baz(Base): DB_TABLE = 'bazs' name = VARCHAR()
class User(Base): DB_TABLE = 'users' id = INT(auto_increment=True, primary_key=True) name = VARCHAR()
class Baz(Base): DB_TABLE = 'bazs' id = DATE(primary_key=True) name = VARCHAR()
class Foo(Base): DB_TABLE = 'foos' id = INT(primary_key=True) foo = VARCHAR()