Skip to content

Commit 8aad14e

Browse files
committed
Add enum values to table_summary and truncate long column values
1 parent 27a4985 commit 8aad14e

12 files changed

Lines changed: 92 additions & 16 deletions

File tree

TODO.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@
99
- changing DB port
1010
- search
1111
- table_summary
12-
13-
14-
## schema include/exclude list in config
15-
16-
## Add enum values to table_summary
17-
## Truncate sampled columns in table_summary

config_example.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,4 @@ databases:
7474
settings:
7575
max_query_timeout: 30
7676
max_rows_per_query: 500
77-
sample_size: 10
7877
enable_write_operations: false

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[project]
22
name = "meeseeql"
3-
version = "0.1.0"
3+
version = "1.0.0"
44
description = "A FastMCP server for exploring SQL databases"
55

6-
requires-python = ">=3.10"
6+
requires-python = ">=3.11"
77

88
authors = [
99
{ name = "Thomas Smith", email = "thomas@apolloagriculture.com" },

src/meeseeql/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,18 @@ async def table_summary(
103103
database: str,
104104
table_name: str,
105105
db_schema: str | None = None,
106-
limit: int = 250,
106+
limit: int = 100,
107107
page: int = 1,
108108
) -> ToolResult:
109-
"""Get table structure including columns and foreign keys with pagination"""
109+
"""Get table structure including columns and foreign keys with pagination
110+
111+
Args:
112+
database: Database name to query
113+
table_name: Name of the table to summarize
114+
db_schema: Optional schema name (uses default schema if not provided)
115+
limit: Maximum items per page (default: 100)
116+
page: Page number (default: 1)
117+
"""
110118
result = await tools.table_summary(
111119
get_or_init_db_manager(), database, table_name, db_schema, limit, page
112120
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT
2+
NULL as column_name,
3+
NULL as enum_values
4+
LIMIT 0
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SELECT
2+
c.column_name,
3+
CASE
4+
WHEN c.data_type = 'enum' THEN
5+
REPLACE(REPLACE(SUBSTRING(c.column_type, 6, CHAR_LENGTH(c.column_type) - 6), '''', ''), ')', '')
6+
ELSE NULL
7+
END as enum_values
8+
FROM information_schema.columns c
9+
WHERE c.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
10+
AND LOWER(c.table_name) = LOWER('{{table_name}}')
11+
AND LOWER(c.table_schema) = LOWER('{{schema_name}}')
12+
AND c.data_type = 'enum'
13+
ORDER BY c.ordinal_position

src/meeseeql/tools/sql/postgresql/columns.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
SELECT
22
c.column_name,
3-
c.data_type,
3+
CASE
4+
WHEN c.data_type = 'USER-DEFINED' THEN c.udt_name
5+
ELSE c.data_type
6+
END as data_type,
47
c.is_nullable,
58
c.column_default
69
FROM information_schema.columns c
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SELECT
2+
c.column_name,
3+
string_agg(e.enumlabel, ', ' ORDER BY e.enumsortorder) as enum_values
4+
FROM information_schema.columns c
5+
JOIN pg_type t ON t.typname = c.udt_name
6+
JOIN pg_enum e ON e.enumtypid = t.oid
7+
WHERE c.table_schema NOT IN ('information_schema', 'pg_catalog')
8+
AND LOWER(c.table_name) = LOWER('{{table_name}}')
9+
AND LOWER(c.table_schema) = LOWER('{{schema_name}}')
10+
AND t.typtype = 'e'
11+
GROUP BY c.column_name, c.ordinal_position
12+
ORDER BY c.ordinal_position
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT
2+
NULL as column_name,
3+
NULL as enum_values
4+
LIMIT 0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT
2+
NULL as column_name,
3+
NULL as enum_values
4+
LIMIT 0

0 commit comments

Comments
 (0)