39
|
1 # -*- coding: utf-8 -*-
|
|
2 #
|
|
3 # Copyright (C) 2005 Edgewall Software
|
|
4 # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
|
|
5 # All rights reserved.
|
|
6 #
|
|
7 # This software is licensed as described in the file COPYING, which
|
|
8 # you should have received as part of this distribution. The terms
|
|
9 # are also available at http://trac.edgewall.com/license.html.
|
|
10 #
|
|
11 # This software consists of voluntary contributions made by many
|
|
12 # individuals. For the exact contribution history, see the revision
|
|
13 # history and logs, available at http://projects.edgewall.com/trac/.
|
|
14 #
|
|
15 # Author: Christopher Lenz <cmlenz@gmx.de>
|
|
16
|
|
17
|
|
18 class Table(object):
|
|
19 """Declare a table in a database schema."""
|
|
20
|
|
21 def __init__(self, name, key=[]):
|
|
22 self.name = name
|
|
23 self.columns = []
|
|
24 self.indices = []
|
|
25 self.key = key
|
|
26 if isinstance(key, basestring):
|
|
27 self.key = [key]
|
|
28
|
|
29 def __getitem__(self, objs):
|
|
30 self.columns = [o for o in objs if isinstance(o, Column)]
|
|
31 self.indices = [o for o in objs if isinstance(o, Index)]
|
|
32 return self
|
|
33
|
|
34
|
|
35 class Column(object):
|
|
36 """Declare a table column in a database schema."""
|
|
37
|
|
38 def __init__(self, name, type='text', size=None, unique=False,
|
|
39 auto_increment=False):
|
|
40 self.name = name
|
|
41 self.type = type
|
|
42 self.size = size
|
|
43 self.auto_increment = auto_increment
|
|
44
|
|
45
|
|
46 class Index(object):
|
|
47 """Declare an index for a database schema."""
|
|
48
|
|
49 def __init__(self, columns):
|
|
50 self.columns = columns
|