乐趣区

关于python:peewee-创建联合索引

class TinyUrl(Model):
    id = BigAutoField()
    user_id = IntegerField(null=False)
    short_uuid = CharField(max_length=255, null=False, help_text='长度为 6 位')
    long_url_hash = CharField(max_length=64, null=False)
    long_url = CharField(max_length=2048, null=False)
    created_at = DateTimeField(
        null=False,
        constraints=[SQL('DEFAULT CURRENT_TIMESTAMP')],
        help_text='应用数据库工夫'
    )
    updated_at = DateTimeField(
        null=False,
        constraints=[SQL('DEFAULT CURRENT_TIMESTAMP'),
            SQL('ON UPDATE CURRENT_TIMESTAMP'),
        ]
    )

    class Meta:
        database = db
        table_name = 'tiny_url'
        indexes = ((('short_uuid',), True),
            (('user_id', 'long_url_hash'), True),
        )


应用 indexes 就能够了

退出移动版