new features

This commit is contained in:
Mark Gregory
2026-11-16 13:41:54 +00:00
parent 87cdc990c3
commit 5338ae5751
16 changed files with 546 additions and 55 deletions
+18
View File
@@ -55,6 +55,24 @@ final class Store {
}
}
func searchConversations(_ term: String) throws -> [Conversation] {
let term = term.trimmingCharacters(in: .whitespacesAndNewlines)
guard !term.isEmpty else { return try conversations() }
return try query("""
SELECT c.id, c.title FROM chats c
WHERE instr(lower(c.title), lower(?)) > 0 OR EXISTS (
SELECT 1 FROM messages m WHERE m.chat=c.id AND instr(lower(m.content), lower(?)) > 0
)
ORDER BY c.rowid DESC
""", [term, term]) {
Conversation(id: try uuid($0, 0), title: string($0, 1))
}
}
func rename(_ id: UUID, title: String) throws {
try mutate("UPDATE chats SET title=? WHERE id=?", [title, id.uuidString])
}
func create(title: String) throws -> Conversation {
let chat = Conversation(id: UUID(), title: title)
try mutate("INSERT INTO chats(id,title) VALUES(?,?)", [chat.id.uuidString, title])