1
2 r"""
3 ========================
4 Constraint Declarators
5 ========================
6
7 Helper functions to define constraints. These will be part of the generated
8 schema modules. Copy or the reference the module where needed. The location is
9 configurable.
10
11 :Copyright:
12
13 Copyright 2010 - 2016
14 Andr\xe9 Malo or his licensors, as applicable
15
16 :License:
17
18 Licensed under the Apache License, Version 2.0 (the "License");
19 you may not use this file except in compliance with the License.
20 You may obtain a copy of the License at
21
22 http://www.apache.org/licenses/LICENSE-2.0
23
24 Unless required by applicable law or agreed to in writing, software
25 distributed under the License is distributed on an "AS IS" BASIS,
26 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 See the License for the specific language governing permissions and
28 limitations under the License.
29
30 """
31 if __doc__:
32
33 __doc__ = __doc__.encode('ascii').decode('unicode_escape')
34 __author__ = r"Andr\xe9 Malo".encode('ascii').decode('unicode_escape')
35 __docformat__ = "restructuredtext en"
36
37 import sqlalchemy as _sa
38
39
40 -def Unique(*columns, **kwargs):
41 """
42 Append unique constraint
43
44 :Parameters:
45 `columns` : ``tuple``
46 Constraint columns
47
48 `kwargs` : ``dict``
49 Additional arguments
50 """
51 columns[0].table.append_constraint(_sa.UniqueConstraint(
52 *columns, **kwargs
53 ))
54
55
57 """
58 Append primary key
59
60 :Parameters:
61 `columns` : ``tuple``
62 Constraint columns
63
64 `kwargs` : ``dict``
65 Additional parameters
66 """
67 columns[0].table.append_constraint(_sa.PrimaryKeyConstraint(
68 *columns, **kwargs
69 ))
70
71
73 """
74 Append foreign key
75
76 :Parameters:
77 `columns` : sequence
78 Source columns
79
80 `refcolumns` : sequence
81 Referred columns
82
83 `kwargs` : ``dict``
84 Additional parameters
85 """
86 columns[0].table.append_constraint(_sa.ForeignKeyConstraint(
87 [col.name for col in columns], refcolumns, link_to_name=True, **kwargs
88 ))
89