refac
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
@@ -319,9 +320,20 @@ class ModelsTable:
|
|||||||
|
|
||||||
tag = filter.get('tag')
|
tag = filter.get('tag')
|
||||||
if tag:
|
if tag:
|
||||||
like_pattern = f'%"{tag.lower()}"%'
|
# SQLite stores JSON text via json.dumps(ensure_ascii=True),
|
||||||
meta_text = func.lower(cast(Model.meta, String))
|
# so non-ASCII chars are \uXXXX-escaped. PostgreSQL native JSONB
|
||||||
stmt = stmt.filter(meta_text.like(like_pattern))
|
# stores literal Unicode. Use the right pattern for each.
|
||||||
|
if db.bind.dialect.name == 'sqlite':
|
||||||
|
if tag.isascii():
|
||||||
|
meta_text = func.lower(cast(Model.meta, String))
|
||||||
|
pattern = f'%{json.dumps(tag.lower())}%'
|
||||||
|
else:
|
||||||
|
meta_text = cast(Model.meta, String)
|
||||||
|
pattern = f'%{json.dumps(tag)}%'
|
||||||
|
else:
|
||||||
|
meta_text = func.lower(cast(Model.meta, String))
|
||||||
|
pattern = f'%{json.dumps(tag.lower(), ensure_ascii=False)}%'
|
||||||
|
stmt = stmt.filter(meta_text.like(pattern))
|
||||||
|
|
||||||
order_by = filter.get('order_by')
|
order_by = filter.get('order_by')
|
||||||
direction = filter.get('direction')
|
direction = filter.get('direction')
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
@@ -292,10 +293,22 @@ class PromptsTable:
|
|||||||
|
|
||||||
tag = filter.get('tag')
|
tag = filter.get('tag')
|
||||||
if tag:
|
if tag:
|
||||||
# Search for tag in JSON array field
|
# SQLite stores JSON text via json.dumps(ensure_ascii=True),
|
||||||
like_pattern = f'%"{tag.lower()}"%'
|
# so non-ASCII chars are \uXXXX-escaped. PostgreSQL native JSONB
|
||||||
tags_text = func.lower(cast(Prompt.tags, String))
|
# stores literal Unicode. Use the right pattern for each.
|
||||||
stmt = stmt.filter(tags_text.like(like_pattern))
|
if db.bind.dialect.name == 'sqlite':
|
||||||
|
if tag.isascii():
|
||||||
|
tags_text = func.lower(cast(Prompt.tags, String))
|
||||||
|
pattern = f'%{json.dumps(tag.lower())}%'
|
||||||
|
else:
|
||||||
|
# LOWER() is ASCII-only; non-ASCII codepoints would
|
||||||
|
# produce different \uXXXX escapes when lowered.
|
||||||
|
tags_text = cast(Prompt.tags, String)
|
||||||
|
pattern = f'%{json.dumps(tag)}%'
|
||||||
|
else:
|
||||||
|
tags_text = func.lower(cast(Prompt.tags, String))
|
||||||
|
pattern = f'%{json.dumps(tag.lower(), ensure_ascii=False)}%'
|
||||||
|
stmt = stmt.filter(tags_text.like(pattern))
|
||||||
|
|
||||||
order_by = filter.get('order_by')
|
order_by = filter.get('order_by')
|
||||||
direction = filter.get('direction')
|
direction = filter.get('direction')
|
||||||
|
|||||||
Reference in New Issue
Block a user