Skip to content

Commit 009f824

Browse files
isra17ilevkivskyi
authored andcommitted
Allow TextClause in Index __init__ (#99)
Quick fix that allow support for: ```python # From official doc from sqlalchemy import text Table("sometable", metadata, Column("name", String(50)), Column("address", String(100)), Index("some_index", text("lower(name)")) ) ```
1 parent 785ed0e commit 009f824

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

sqlalchemy-stubs/sql/schema.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from typing import (
44
)
55
from . import visitors, functions
66
from .base import SchemaEventTarget as SchemaEventTarget, DialectKWArgs as DialectKWArgs, ColumnCollection
7-
from .elements import ColumnClause as ColumnClause
7+
from .elements import ColumnClause as ColumnClause, TextClause
88
from .selectable import TableClause as TableClause
99
from .type_api import TypeEngine
1010
from .. import util
@@ -304,8 +304,8 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem):
304304
name: str = ...
305305
unique: bool = ...
306306
info: Optional[Mapping[str, Any]] = ...
307-
def __init__(self, name: str, *expressions: Union[Column[Any], str], unique: bool = ..., quote: Optional[bool] = ...,
308-
info: Optional[Mapping[str, Any]] = ..., **kw: Any) -> None: ...
307+
def __init__(self, name: str, *expressions: Union[TextClause, Column[Any], str], unique: bool = ...,
308+
quote: Optional[bool] = ..., info: Optional[Mapping[str, Any]] = ..., **kw: Any) -> None: ...
309309
@property
310310
def bind(self) -> Optional[Union[Engine, Connection]]: ...
311311
def create(self: _I, bind: Optional[Union[Engine, Connection]] = ...) -> _I: ...

test/test-data/sqlalchemy-sql-schema.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ class Mytable(Base):
6060
__tablename__ = 'mytable'
6161
objid = Column(ForeignKey('othertable.objid'), index=True)
6262
[out]
63+
64+
[case testTableWithIndexes]
65+
from sqlalchemy import Column, Table, String, Integer, Index, MetaData, text, func
66+
metadata = MetaData()
67+
name_col = Column('name', String)
68+
test_table = Table('test', metadata,
69+
Column('id', Integer, primary_key=True),
70+
name_col,
71+
Index('idx1', 'id', 'name'),
72+
Index('idx1', 'id', name_col),
73+
Index('idx1', 'id', func.lower(name_col)),
74+
Index('idx1', 'id', text("lower(name)")),
75+
)
76+
[out]

0 commit comments

Comments
 (0)