peewee - Peewee 原生压缩而不是 CompressedField
问题描述
我正在使用 peewee,我想在 MariaDB 中使用压缩字段。该表是通过 SQL 创建的,如下所示:
CREATE TABLE TableName
(
field_name BLOB COMPRESSED,
);
在 peeweeCompressedField
中是一个包装器BlobField
。并非所有访问数据库的用户都使用 peewee,所以我想在 MariaDB 中使用 InnoDB 的内置透明压缩。使用 peewee 时如何告诉 peewee 创建field_name
带有压缩的字段create_tables()
?
解决方案
您可以非常轻松地添加自定义字段类型。这在文档中有所描述:
http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field
这应该是您所需要的:
class CompressedBlobField(BlobField):
field_type = 'BLOB COMPRESSED'
推荐阅读
- python - 检查熊猫数据框的最后一行是否满足条件的最佳方法是什么?
- reactjs - 如何从对回调 URL 的响应中提取数据?
- azure-functions - 使用 CLI 创建 Azure Function 项目
- typescript - 谷歌地图没有显示 Javascript Ionic 4
- ssl - 获取剩余有效期的 SSL 证书的证书错误
- spring - JUnit 测试:NoSuchBeanDefinitionException:没有符合条件的 bean 类型
- google-cloud-run - ENV 变量中的 Google Cloud Run 和 JSON
- php - 致命错误:存在时找不到类“conn”
- node.js - “找不到所需的文件。名称:index.html”在 Heroku 上部署 React 应用程序时出错
- javascript - TimerTask 完成不会使 Task.any 产生已完成的任务