MCPcopy Create free account
hub / github.com/LazyAGI/LazyCraft / load_dialect_impl

Method load_dialect_impl

back/src/models/__init__.py:60–88  ·  view source on GitHub ↗

根据不同的数据库方言加载适当的类型实现。 为不同的数据库选择最优的存储类型: - PostgreSQL: 优先使用原生 UUID 类型 - MySQL: 使用 MySQL 优化的 CHAR 类型 - 其他: 使用标准 CHAR 类型 Args: dialect: SQLAlchemy 数据库方言对象 Returns: 适合当前数据库的类型描述符

(self, dialect)

Source from the content-addressed store, hash-verified

58 super().__init__()
59
60 def load_dialect_impl(self, dialect):
61 """
62 根据不同的数据库方言加载适当的类型实现。
63
64 为不同的数据库选择最优的存储类型:
65 - PostgreSQL: 优先使用原生 UUID 类型
66 - MySQL: 使用 MySQL 优化的 CHAR 类型
67 - 其他: 使用标准 CHAR 类型
68
69 Args:
70 dialect: SQLAlchemy 数据库方言对象
71
72 Returns:
73 适合当前数据库的类型描述符
74 """
75 if dialect.name == "postgresql":
76 # PostgreSQL 有原生 UUID 支持,性能更好
77 try:
78 return dialect.type_descriptor(PostgreSQLUUID())
79 except ImportError:
80 # 如果 PostgreSQL 驱动不支持 UUID,回退到 CHAR
81 logger.warning("PostgreSQL UUID 类型不可用,回退到 CHAR 类型")
82 return dialect.type_descriptor(CHAR(self.length))
83 elif dialect.name == "mysql":
84 # MySQL 使用专门优化的 CHAR 类型
85 return dialect.type_descriptor(MySQLChar(self.length))
86 else:
87 # 其他数据库使用标准 CHAR 类型
88 return dialect.type_descriptor(CHAR(self.length))
89
90 def process_bind_param(self, value: Any, dialect) -> Optional[str]:
91 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected