schema_3_extractor

mcp_ohmy_sql.db.relational.schema_3_extractor.get_sqlalchemy_type_mapping() dict[str, LLMTypeEnum][source]

Get the SQLAlchemy type mapping dictionary.

This function returns a dictionary that maps SQLAlchemy type visit names to simplified LLM type constants. It is used to convert SQLAlchemy types to a format suitable for LLM consumption.

mcp_ohmy_sql.db.relational.schema_3_extractor.SQLALCHEMY_TYPE_MAPPING = {'ARRAY': LLMTypeEnum.STR, 'BIGINT': LLMTypeEnum.INT, 'BINARY': LLMTypeEnum.BIN, 'BLOB': LLMTypeEnum.BLOB, 'BOOLEAN': LLMTypeEnum.BOOL, 'CHAR': LLMTypeEnum.STR, 'CLOB': LLMTypeEnum.STR, 'DATE': LLMTypeEnum.DATE, 'DATETIME': LLMTypeEnum.DT, 'DECIMAL': LLMTypeEnum.DEC, 'DOUBLE': LLMTypeEnum.FLOAT, 'DOUBLE_PRECISION': LLMTypeEnum.FLOAT, 'FLOAT': LLMTypeEnum.FLOAT, 'INTEGER': LLMTypeEnum.INT, 'JSON': LLMTypeEnum.STR, 'JSONB': LLMTypeEnum.BLOB, 'NCHAR': LLMTypeEnum.STR, 'NUMERIC': LLMTypeEnum.DEC, 'NVARCHAR': LLMTypeEnum.STR, 'REAL': LLMTypeEnum.FLOAT, 'SMALLINT': LLMTypeEnum.INT, 'TEXT': LLMTypeEnum.STR, 'TIME': LLMTypeEnum.TIME, 'TIMESTAMP': LLMTypeEnum.TS, 'UUID': LLMTypeEnum.STR, 'VARBINARY': LLMTypeEnum.BIN, 'VARCHAR': LLMTypeEnum.STR, 'big_integer': LLMTypeEnum.INT, 'boolean': LLMTypeEnum.BOOL, 'date': LLMTypeEnum.DATE, 'datetime': LLMTypeEnum.DT, 'double': LLMTypeEnum.FLOAT, 'enum': LLMTypeEnum.STR, 'float': LLMTypeEnum.FLOAT, 'integer': LLMTypeEnum.INT, 'large_binary': LLMTypeEnum.BLOB, 'null': LLMTypeEnum.NULL, 'numeric': LLMTypeEnum.DEC, 'small_integer': LLMTypeEnum.INT, 'string': LLMTypeEnum.STR, 'text': LLMTypeEnum.STR, 'time': LLMTypeEnum.TIME, 'type_decorator': LLMTypeEnum.STR, 'unicode': LLMTypeEnum.STR, 'unicode_text': LLMTypeEnum.STR, 'uuid': LLMTypeEnum.STR}

Mapping from SQLAlchemy type visit names to simplified LLM type constants.

This dictionary maps SQLAlchemy’s internal type visit names (used for type introspection) to our simplified type constants that are more suitable for LLM consumption. The mapping covers all standard SQLAlchemy types including:

  • Generic types (e.g., String, Integer, Float)

  • SQL standard types (e.g., VARCHAR, BIGINT, TIMESTAMP)

  • Special types (e.g., JSON, UUID, Enum)

The visit name is accessed via type.__visit_name__ for each SQLAlchemy type instance.

mcp_ohmy_sql.db.relational.schema_3_extractor.sqlalchemy_type_to_llm_type(type_: TypeEngine) LLMTypeEnum[source]

Convert SQLAlchemy type objects to simplified type representations suitable for LLM consumption. It handles both generic SQLAlchemy types (e.g., String, Integer) and SQL standard types (e.g., VARCHAR, BIGINT).

Parameters:

type – A SQLAlchemy TypeEngine instance representing a column type

Returns:

A new llm type name

Example:
>>> from sqlalchemy import String, Integer, DECIMAL
>>> sqlalchemy_type_to_llm_type(String(50))
'STR'
>>> sqlalchemy_type_to_llm_type(Integer())
'INT'
>>> sqlalchemy_type_to_llm_type(DECIMAL(10, 2))
'DEC'
mcp_ohmy_sql.db.relational.schema_3_extractor.new_foreign_key_info(foreign_key: ForeignKey) ForeignKeyInfo[source]

Create a new ForeignKeyInfo object from a SQLAlchemy ForeignKey object.

mcp_ohmy_sql.db.relational.schema_3_extractor.new_column_info(table: Table, column: Column) ColumnInfo[source]

Create a new ColumnInfo object from a SQLAlchemy Column object.

mcp_ohmy_sql.db.relational.schema_3_extractor.new_table_info(table: Table, object_type: ObjectTypeEnum) TableInfo[source]

Create a new TableInfo object from a SQLAlchemy Table object.

mcp_ohmy_sql.db.relational.schema_3_extractor.new_schema_info(engine: Engine, metadata: MetaData, schema_name: str | None = None, include: list[str] | None = None, exclude: list[str] | None = None) SchemaInfo[source]

Create a new SchemaInfo object from a SQLAlchemy Engine and MetaData.

mcp_ohmy_sql.db.relational.schema_3_extractor.new_database_info(name: str, db_type: DbTypeEnum, schemas: list[SchemaInfo], comment: str | None = None) DatabaseInfo[source]

Create a new DatabaseInfo object.