utils

mcp_ohmy_sql.utils.match(name: str, include: list[str], exclude: list[str]) bool[source]

Match a name against include and exclude lists using wildcard or regex patterns.

The include/exclude pattern system works like a two-stage filter where name must pass both inclusion and exclusion criteria to be selected for processing.

Pattern Types:

  • Wildcard patterns: Use * to match any characters (e.g., "EMPLOYEE*", "*_TEMP")

  • Regex patterns: Automatically detected when regex metacharacters are present (e.g., "^EMP.*", ".*_TABLE$", "[A-Z]+_\d+")

Matching Rules:

  • Default inclusion: When include list is empty, all names are included by default

  • Include matching: When include patterns exist, a name must match ANY include pattern (logical OR) to be considered

  • Exclude override: If a name matches ANY exclude pattern, it’s rejected regardless of include matches

  • Case insensitive: All pattern matching is case-insensitive

Parameters:
  • name – The name to match (e.g., table name, column name)

  • include – List of patterns to include. Empty list means include all.

  • exclude – List of patterns to exclude. Takes precedence over include.

Returns:

bool: True if the name matches the criteria, False otherwise.

Examples:
>>> # Include all employee tables
>>> match("EMPLOYEES", ["EMPLOYEE*"], [])
True
>>> match("EMPLOYEE_HISTORY", ["EMPLOYEE*"], [])
True
>>> match("MANAGERS", ["EMPLOYEE*"], [])
False
>>> # Include all, but exclude temporary tables
>>> match("USERS", [], ["*_TEMP", "*_TMP"])
True
>>> match("USERS_TEMP", [], ["*_TEMP", "*_TMP"])
False
>>> # Include specific tables with regex
>>> match("EMP_2023", ["^EMP_\d{4}$"], [])
True
>>> match("EMP_ARCHIVE", ["^EMP_\d{4}$"], [])
False
>>> # Complex filtering: include employee/manager tables, exclude history
>>> match("EMPLOYEE_CURRENT", ["EMPLOYEE*", "MANAGER*"], ["*_HISTORY"])
True
>>> match("EMPLOYEE_HISTORY", ["EMPLOYEE*", "MANAGER*"], ["*_HISTORY"])
False
>>> # Case insensitive matching
>>> match("employees", ["EMPLOYEES"], [])
True
>>> match("EMPLOYEES", ["employees"], [])
True
mcp_ohmy_sql.utils.dedent(text: str) str[source]

Dedent a string by removing common leading whitespace.

This is useful for cleaning up multi-line strings that may have inconsistent indentation levels.

Parameters:

text – The input string to dedent.

Returns:

A dedented version of the input string.