Search code examples
peewee

Peewee Native compression instead of CompressedField


I am using peewee and I'd like to use compressed field in MariaDB. The table is created like this via SQL:

CREATE TABLE TableName
(
    field_name   BLOB COMPRESSED,
);

In peewee CompressedField is a wrapper around BlobField. Not all of my users accessing the database use peewee so I would like to use the built-in transparent compression of InnoDB in MariaDB. How do I tell peewee to create the field field_name with compression when using peewee's create_tables()?


Solution

  • You can very very easily add a custom field type. This is described in the docs:

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

    This should be all you need:

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