【Python】peeweeで部分一致のOR検索

【Python】peeweeで部分一致のOR検索する方法です。

サンプリコードは以下の通りです。

import Page
import operator
clauses = [
(Page.title.contains("hoge")),
(Page.title.contains("fuga"))
]
Page.select().where(reduce(operator.or_, clauses))
"""
SELECT * FROM page WHERE (title LIKE '%hoge%' OR title LIKE '%huga%')
"""
view raw or.py hosted with ❤ by GitHub

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This site uses Akismet to reduce spam. Learn how your comment data is processed.