montevibiano-industry-coditech/app/schemas.py
2025-09-26 15:29:31 +02:00

26 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from typing import Any, Dict, Optional
from pydantic import BaseModel, Field
class ConnectionPayload(BaseModel):
server: str = Field(..., example="mssql.example.local,1433")
database: str = Field(..., example="MyDb")
username: Optional[str] = Field(None, example="sa")
password: Optional[str] = Field(None, example="S3cret!")
# For servers with encryption disabled, set encrypt=False (default below)
encrypt: bool = Field(default=False, description="ODBC Encrypt setting: yes/no")
trust_server_certificate: bool = Field(
default=True,
description="If encrypt=True and you dont have CA chain, set True"
)
timeout: int = Field(default=15, ge=1, le=120)
class QueryPayload(ConnectionPayload):
sql: str = Field(..., example="SELECT TOP 5 id, name FROM dbo.Customers WHERE city = :city")
params: Dict[str, Any] = Field(default_factory=dict)
max_rows: Optional[int] = Field(None, ge=1, example=1000)
class ExecutePayload(ConnectionPayload):
sql: str = Field(..., example="UPDATE dbo.Customers SET name = :name WHERE id = :id")
params: Dict[str, Any] = Field(default_factory=dict)
autocommit: bool = Field(default=False)