Mercurial > genshi > mirror
view examples/trac/trac/db/schema.py @ 39:93b4dcbafd7b trunk
Copy Trac to main branch.
author | cmlenz |
---|---|
date | Mon, 03 Jul 2006 18:53:27 +0000 |
parents | |
children |
line wrap: on
line source
# -*- coding: utf-8 -*- # # Copyright (C) 2005 Edgewall Software # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de> # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://trac.edgewall.com/license.html. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://projects.edgewall.com/trac/. # # Author: Christopher Lenz <cmlenz@gmx.de> class Table(object): """Declare a table in a database schema.""" def __init__(self, name, key=[]): self.name = name self.columns = [] self.indices = [] self.key = key if isinstance(key, basestring): self.key = [key] def __getitem__(self, objs): self.columns = [o for o in objs if isinstance(o, Column)] self.indices = [o for o in objs if isinstance(o, Index)] return self class Column(object): """Declare a table column in a database schema.""" def __init__(self, name, type='text', size=None, unique=False, auto_increment=False): self.name = name self.type = type self.size = size self.auto_increment = auto_increment class Index(object): """Declare an index for a database schema.""" def __init__(self, columns): self.columns = columns