-
Notifications
You must be signed in to change notification settings - Fork 392
Expand file tree
/
Copy pathsql.py
More file actions
29 lines (21 loc) · 781 Bytes
/
sql.py
File metadata and controls
29 lines (21 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from __future__ import absolute_import, division, print_function
from .compatibility import basestring
from .dispatch import dispatch
try:
import sqlalchemy as sa
from sqlalchemy import Table
except ImportError:
Table = type(None)
__all__ = ()
@dispatch(Table, basestring)
def create_index(s, column, name=None, unique=False):
if name is None:
raise ValueError('SQL indexes must have a name')
sa.Index(name, getattr(s.c, column), unique=unique).create(s.bind)
@dispatch(Table, list)
def create_index(s, columns, name=None, unique=False):
if name is None:
raise ValueError('SQL indexes must have a name')
args = name,
args += tuple(getattr(s.c, column) for column in columns)
sa.Index(*args, unique=unique).create(s.bind)