跨数据库SQLAlchemy应用程序的通用TEXT / CLOB数据类型 [英] Generic TEXT/CLOB data type for cross-database SQLAlchemy application
问题描述
我正在使用Python Web应用程序,它使用MySQL作为开发环境中的数据库后端和生产环境中的Oracle 11g。有没有具体的方法统一SQLAlchemy文本字段,以便他们在MySQL和Oracle数据库上工作?对于模型中的Oracle后端,我使用 sqlalchemy.CLOB
和MySQL sqlalchemy.TEXT
。
I am working on Python web application that uses MySQL as a database backend on the development environment and Oracle 11g on the production environment. Is there a specific way to unify the SQLAlchemy text fields, so that they work both on MySQL and Oracle database? For the Oracle backend in the models I use sqlalchemy.CLOB
and for MySQL sqlalchemy.TEXT
.
推荐答案
根据@agronholm #sqlalchemy,应该使用通用SQLAlchemy类型 Text
(其中 TEXT
是特殊化的):
According to @agronholm on #sqlalchemy one is supposed to use generic SQLAlchemy type Text
(which TEXT
is specialization of):
大小可变的字符串类型。
A variably sized string type.
在SQL中,通常对应于CLOB或TEXT。还可以使用Python
unicode对象,并在绑定参数
中编码到数据库的编码(结果集的反向)。一般来说,TEXT对象不会
有长度;而一些数据库将在这里接受长度参数
,它将被其他人拒绝。
In SQL, usually corresponds to CLOB or TEXT. Can also take Python unicode objects and encode to the database’s encoding in bind params (and the reverse for result sets.) In general, TEXT objects do not have a length; while some databases will accept a length argument here, it will be rejected by others.
这篇关于跨数据库SQLAlchemy应用程序的通用TEXT / CLOB数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!