MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / get_indexes

Method get_indexes

lib/sqlalchemy/dialects/mysql/base.py:3554–3607  ·  view source on GitHub ↗
(
        self,
        connection: Connection,
        table_name: str,
        schema: Optional[str] = None,
        **kw: Any,
    )

Source from the content-addressed store, hash-verified

3552
3553 @reflection.cache
3554 def get_indexes(
3555 self,
3556 connection: Connection,
3557 table_name: str,
3558 schema: Optional[str] = None,
3559 **kw: Any,
3560 ) -> List[ReflectedIndex]:
3561 parsed_state = self._parsed_state_or_create(
3562 connection, table_name, schema, **kw
3563 )
3564
3565 indexes: List[ReflectedIndex] = []
3566
3567 for spec in parsed_state.keys:
3568 dialect_options = {}
3569 unique = False
3570 flavor = spec["type"]
3571 if flavor == "PRIMARY":
3572 continue
3573 if flavor == "UNIQUE":
3574 unique = True
3575 elif flavor in ("FULLTEXT", "SPATIAL"):
3576 dialect_options["%s_prefix" % self.name] = flavor
3577 elif flavor is not None:
3578 util.warn(
3579 "Converting unknown KEY type %s to a plain KEY", flavor
3580 )
3581
3582 if spec["parser"]:
3583 dialect_options["%s_with_parser" % (self.name)] = spec[
3584 "parser"
3585 ]
3586
3587 index_d: ReflectedIndex = {
3588 "name": spec["name"],
3589 "column_names": [s[0] for s in spec["columns"]],
3590 "unique": unique,
3591 }
3592
3593 mysql_length = {
3594 s[0]: s[1] for s in spec["columns"] if s[1] is not None
3595 }
3596 if mysql_length:
3597 dialect_options["%s_length" % self.name] = mysql_length
3598
3599 if flavor:
3600 index_d["type"] = flavor # type: ignore[typeddict-unknown-key]
3601
3602 if dialect_options:
3603 index_d["dialect_options"] = dialect_options
3604
3605 indexes.append(index_d)
3606 indexes.sort(key=lambda d: d["name"] or "~") # sort None as last
3607 return indexes if indexes else ReflectionDefaults.indexes()
3608
3609 @reflection.cache
3610 def get_unique_constraints(

Callers

nothing calls this directly

Calls 5

indexesMethod · 0.80
warnMethod · 0.45
appendMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected