new features
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user