From 6321a9e7e0b85adfd0946736b7a5c0224eb03615 Mon Sep 17 00:00:00 2001 From: LambdaYH Date: Mon, 22 Aug 2022 00:49:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8gino=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E9=81=BF=E5=85=8D=E6=9E=84?= =?UTF-8?q?=E5=BB=BAsql=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=97=B6=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E9=9D=9E=E6=B3=95=E6=9F=A5=E8=AF=A2=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/_model.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/word_bank/_model.py b/plugins/word_bank/_model.py index 3759cd58..2eec7b00 100644 --- a/plugins/word_bank/_model.py +++ b/plugins/word_bank/_model.py @@ -234,16 +234,27 @@ class WordBank(db.Model): query = query.where(cls.word_scope == word_type) sql_text += f" and word_scope = {word_scope}" # 完全匹配 - if await query.where(((cls.word_type == 0) | (cls.word_type == 3)) & (cls.problem == problem)).gino.first(): + if await query.where( + ((cls.word_type == 0) | (cls.word_type == 3)) & (cls.problem == problem) + ).gino.first(): return query.where(cls.problem == problem) # 模糊匹配 - if await query.where((cls.word_type == 1) & (cls.problem.contains(problem))).gino.first(): + if await query.where( + (cls.word_type == 1) & (cls.problem.contains(problem)) + ).gino.first(): return query.where(cls.problem.contains(problem)) # 正则匹配 if await db.first( - db.text(sql_text + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;") + db.text( + sql_text + + f" and word_type = 2 and word_scope != 999 and :problem ~ problem;" + ), + problem=problem, ): - return sql_text + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;" + return ( + sql_text + + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;" + ) # if await db.first( # db.text(sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;") # ): @@ -458,4 +469,4 @@ class WordBank(db.Model): ) problem_list.append(problem) _tmp.append(q.problem) - return problem_list \ No newline at end of file + return problem_list