Initial Codes

This commit is contained in:
2026-05-21 15:46:41 -04:00
commit b01ad5ea40
40 changed files with 9102 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
"""
Connection profile dataclass and registry.
"""
from dataclasses import dataclass, field
from typing import Optional
import uuid
@dataclass
class ConnectionProfile:
name: str
db_type: str # mysql | postgresql | sqlite | mssql
host: str = "localhost"
port: int = 3306
database: str = ""
username: str = ""
color: str = "#89b4fa"
id: str = field(default_factory=lambda: str(uuid.uuid4()))
ssl: bool = False
ssl_cert: str = ""
ssl_key: str = ""
ssl_ca: str = ""
connection_timeout: int = 30
DB_PORTS = {
"mysql": 3306,
"postgresql": 5432,
"sqlite": 0,
"mssql": 1433,
}
DB_DISPLAY = {
"mysql": "MySQL",
"postgresql": "PostgreSQL",
"sqlite": "SQLite",
"mssql": "SQL Server",
}
@property
def db_type_display(self) -> str:
return self.DB_DISPLAY.get(self.db_type, self.db_type)
@property
def default_port(self) -> int:
return self.DB_PORTS.get(self.db_type, 0)
def to_dict(self) -> dict:
return {
"id": self.id,
"name": self.name,
"db_type": self.db_type,
"host": self.host,
"port": self.port,
"database": self.database,
"username": self.username,
"color": self.color,
"ssl": self.ssl,
"ssl_cert": self.ssl_cert,
"ssl_key": self.ssl_key,
"ssl_ca": self.ssl_ca,
"connection_timeout": self.connection_timeout,
}
@classmethod
def from_dict(cls, data: dict) -> "ConnectionProfile":
return cls(
id=data.get("id", str(uuid.uuid4())),
name=data.get("name", "Untitled"),
db_type=data.get("db_type", "mysql"),
host=data.get("host", "localhost"),
port=data.get("port", 3306),
database=data.get("database", ""),
username=data.get("username", ""),
color=data.get("color", "#89b4fa"),
ssl=data.get("ssl", False),
ssl_cert=data.get("ssl_cert", ""),
ssl_key=data.get("ssl_key", ""),
ssl_ca=data.get("ssl_ca", ""),
connection_timeout=data.get("connection_timeout", 30),
)