如何在可变数组中使用SQLAlchemy进行搜索

2024-09-29 23:25:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用可变数组来存储SQLAlchemy和Postgres中的数据,并编写了以下类:

class MutableList(Mutable, list):
    def append(self, value):
        list.append(self, value)
        self.changed()

    def pop(self, index=0):
        value = list.pop(self, index)
        self.changed()
        return value

    @classmethod
    def coerce(cls, key, value):
        if not isinstance(value, MutableList):
            if isinstance(value, list):
                return MutableList(value)
            return Mutable.coerce(key, value)
        else:
            return value


class Lead(db.Model):
    __tablename__ = 'leads'

    ...
    starred = db.Column(MutableList.as_mutable(db.ARRAY(db.Integer)))

我可以更新started属性,从中添加和弹出项目。我的问题是如何搜索数组中具有特定项的行。我的问题是:

^{pr2}$

但这给了我以下错误:ARRAY.contains() not implemented for the base ARRAY type; please use the dialect-specific ARRAY type

我错过了什么?在


Tags: selfdbindexreturnvaluedef数组array

热门问题