43 lines
784 B
Python
43 lines
784 B
Python
# -*- coding: utf-8 -*-
|
|
"""数据库查看器 Pydantic 模型
|
|
|
|
定义 Schema 浏览、表结构查看、SQL 查询的请求/响应模型。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class SchemaInfo(BaseModel):
|
|
"""Schema 信息。"""
|
|
name: str
|
|
|
|
|
|
class TableInfo(BaseModel):
|
|
"""表信息(含行数统计)。"""
|
|
name: str
|
|
row_count: int | None = None
|
|
|
|
|
|
class ColumnInfo(BaseModel):
|
|
"""列定义。"""
|
|
name: str
|
|
data_type: str
|
|
is_nullable: bool
|
|
column_default: str | None = None
|
|
|
|
|
|
class QueryRequest(BaseModel):
|
|
"""SQL 查询请求。"""
|
|
sql: str
|
|
|
|
|
|
class QueryResponse(BaseModel):
|
|
"""SQL 查询响应。"""
|
|
columns: list[str]
|
|
rows: list[list[Any]]
|
|
row_count: int
|