sqlmeta.objects.index

Classes

Index(name, table_name, columns[, schema, ...])

Represents a database index.

class sqlmeta.objects.index.Index(name: str, table_name: str, columns: List[str], schema: str | None = None, table_schema: str | None = None, unique: bool = False, type: str = 'BTREE', condition: str | None = None, include_columns: List[str] | None = None, sort_directions: List[str] | None = None, dialect: str | None = None, online: bool | None = None, concurrently: bool = False, tablespace: str | None = None)[source]

Represents a database index.

__init__(name: str, table_name: str, columns: List[str], schema: str | None = None, table_schema: str | None = None, unique: bool = False, type: str = 'BTREE', condition: str | None = None, include_columns: List[str] | None = None, sort_directions: List[str] | None = None, dialect: str | None = None, online: bool | None = None, concurrently: bool = False, tablespace: str | None = None)[source]

Initialize an index.

Parameters:
  • name – Index name

  • table_name – Name of the table being indexed

  • columns – List of indexed columns

  • schema – Schema name for the index

  • table_schema – Schema name for the table (if different from index schema)

  • unique – Whether this is a unique index

  • type – Index type (BTREE, HASH, FULLTEXT, SPATIAL, etc.)

  • condition – Optional WHERE condition

  • include_columns – Optional INCLUDE columns (SQL Server)

  • sort_directions – Optional sort directions (ASC/DESC) for each column

  • dialect – SQL dialect

  • online – Whether index was created with ONLINE (True) or OFFLINE (False) (MySQL grammar-based)

  • concurrently – Whether index was created CONCURRENTLY (PostgreSQL grammar-based)

  • tablespace – Tablespace name for the index (Oracle grammar-based)

property create_statement: str

Generate CREATE INDEX statement.

The syntax varies by dialect.

Returns:

Dialect-specific CREATE INDEX statement

property drop_statement: str

Generate DROP INDEX statement.

Returns:

SQL DROP INDEX statement for this index

classmethod from_dict(data: Dict[str, Any]) Index[source]

Create index from dictionary representation.

Parameters:

data – Dictionary with index attributes

Returns:

Index object

to_dict() Dict[str, Any][source]

Convert index to dictionary representation.

Returns:

Dictionary with index attributes