Skip to content

Tests #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 7, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TESTS
  • Loading branch information
rmusser01 committed Jun 7, 2025
commit 7ebdcc07313f49d6e02a7e284f44d056fe60c9da
File renamed without changes.
1,119 changes: 1,119 additions & 0 deletions Tests/Prompts_DB/tests_prompts_db.py

Large diffs are not rendered by default.

574 changes: 574 additions & 0 deletions Tests/Prompts_DB/tests_prompts_db_properties.py

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
22 changes: 16 additions & 6 deletions tldw_chatbook/DB/Prompts_DB.py
Original file line number Diff line number Diff line change
@@ -1121,7 +1121,8 @@ def soft_delete_keyword(self, keyword_text: str) -> bool:
def get_prompt_by_id(self, prompt_id: int, include_deleted: bool = False) -> Optional[Dict]:
query = "SELECT * FROM Prompts WHERE id = ?"
params = [prompt_id]
if not include_deleted: query += " AND deleted = 0"
if not include_deleted:
query += " AND deleted = 0"
try:
cursor = self.execute_query(query, tuple(params))
result = cursor.fetchone()
@@ -1133,7 +1134,8 @@ def get_prompt_by_id(self, prompt_id: int, include_deleted: bool = False) -> Opt
def get_prompt_by_uuid(self, prompt_uuid: str, include_deleted: bool = False) -> Optional[Dict]:
query = "SELECT * FROM Prompts WHERE uuid = ?"
params = [prompt_uuid]
if not include_deleted: query += " AND deleted = 0"
if not include_deleted:
query += " AND deleted = 0"
try:
cursor = self.execute_query(query, tuple(params))
result = cursor.fetchone()
@@ -1145,7 +1147,8 @@ def get_prompt_by_uuid(self, prompt_uuid: str, include_deleted: bool = False) ->
def get_prompt_by_name(self, name: str, include_deleted: bool = False) -> Optional[Dict]:
query = "SELECT * FROM Prompts WHERE name = ?"
params = [name]
if not include_deleted: query += " AND deleted = 0"
if not include_deleted:
query += " AND deleted = 0"
try:
cursor = self.execute_query(query, tuple(params))
result = cursor.fetchone()
@@ -1268,14 +1271,15 @@ def search_prompts(self,

# FTS on prompt fields
if fts_query_parts:
fts_conditions = []
fts_search_active = True
if not any("prompts_fts fts_p" in j_item for j_item in joins):
joins.append("JOIN prompts_fts fts_p ON fts_p.rowid = p.id")
# Build FTS query: field1:query OR field2:query ...
# For simple matching, just use the query directly if FTS table covers all these.
# The FTS table definition needs to match these fields.
# Assuming prompts_fts has 'name', 'author', 'details', 'system_prompt', 'user_prompt'
conditions.append("fts_p.prompts_fts MATCH ?")
fts_conditions.append("fts_p.prompts_fts MATCH ?")
params.append(search_query) # User provides FTS syntax or simple terms

# FTS on keywords (if specified in search_fields)
@@ -1289,8 +1293,14 @@ def search_prompts(self,
if not any("prompt_keywords_fts fts_k" in j_item for j_item in joins):
joins.append("JOIN prompt_keywords_fts fts_k ON fts_k.rowid = pkw.id")

conditions.append("fts_k.prompt_keywords_fts MATCH ?")
params.append(search_query) # Match against keywords
# Create an OR-ed condition for keywords
fts_conditions.append("fts_k.prompt_keywords_fts MATCH ?")
params.append(search_query) # Re-add param for this clause

# Combine the FTS conditions with OR
if fts_conditions:
conditions.append(f"({' OR '.join(fts_conditions)})")
fts_search_active = True

order_by_clause_str = "ORDER BY p.last_modified DESC, p.id DESC"
if fts_search_active: