在SQLAlchemy中,如何指定全文索引?

发布于 2025-01-03 20:29:49 字数 353 浏览 1 评论 0原文

class AccountIndexes(Base):
    __tablename__ = 'account_indexes'
    id = Column(Integer, primary_key = True)
    user_id = Column(Integer, nullable=False, unique=True, index=True)
    full_name = Column(String(255), nullable=True)
    __table_args__ = {'mysql_engine':'MyISAM'}

那是我的桌子。如何在 full_name 上创建“全文索引”? (不是普通索引)

class AccountIndexes(Base):
    __tablename__ = 'account_indexes'
    id = Column(Integer, primary_key = True)
    user_id = Column(Integer, nullable=False, unique=True, index=True)
    full_name = Column(String(255), nullable=True)
    __table_args__ = {'mysql_engine':'MyISAM'}

That's my table. How do I make a "full text index" on full_name? (not a normal index)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰之心 2025-01-10 20:29:49

如果您可以检查 sqlalchemy.schemaIndex 中的代码,那么他们

def __init__(self, name, *columns, **kw):
    """Construct an index object.

    :param name:
      The name of the index

    :param \*columns:
      Columns to include in the index. All columns must belong to the same
      table.

    :param unique:
        Defaults to False: create a unique index.

    :param \**kw:
        Other keyword arguments may be interpreted by specific dialects.

    """
    self.table = None 
    # will call _set_parent() if table-bound column
    # objects are present
    ColumnCollectionMixin.__init__(self, *columns)
    self.name = name 
    self.unique = kw.pop('unique', False)
    self.kwargs = kw 

Index__init__ 中写入 Now只检查唯一。我认为要生成全文索引,您必须使用 sqlalchemy 的 DDL 操作功能。

If you can check the code in Index of sqlalchemy.schema then they wrote

def __init__(self, name, *columns, **kw):
    """Construct an index object.

    :param name:
      The name of the index

    :param \*columns:
      Columns to include in the index. All columns must belong to the same
      table.

    :param unique:
        Defaults to False: create a unique index.

    :param \**kw:
        Other keyword arguments may be interpreted by specific dialects.

    """
    self.table = None 
    # will call _set_parent() if table-bound column
    # objects are present
    ColumnCollectionMixin.__init__(self, *columns)
    self.name = name 
    self.unique = kw.pop('unique', False)
    self.kwargs = kw 

Now in __init__ of the Index they only check the unique. I think to generate fulltext index you have to use DDL manipulation functionality of sqlalchemy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文