首页 > 解决方案 > Peewee 原生压缩而不是 CompressedField

问题描述

我正在使用 peewee,我想在 MariaDB 中使用压缩字段。该表是通过 SQL 创建的,如下所示:

CREATE TABLE TableName
(
    field_name   BLOB COMPRESSED,
);

在 peeweeCompressedField中是一个包装器BlobField。并非所有访问数据库的用户都使用 peewee,所以我想在 MariaDB 中使用 InnoDB 的内置透明压缩。使用 peewee 时如何告诉 peewee 创建field_name带有压缩的字段create_tables()

标签: peewee

解决方案


您可以非常轻松地添加自定义字段类型。这在文档中有所描述:

http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field

这应该是您所需要的:

class CompressedBlobField(BlobField):
    field_type = 'BLOB COMPRESSED'

推荐阅读