Client
Client interface for interacting with the database in CodeMap.
logger
module-attribute
logger = getLogger(__name__)
DatabaseClient
Provides high-level methods to interact with the CodeMap database.
Source code in src/codemap/db/client.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
__init__
__init__() -> None
Initializes the database client.
It sets up the client in an uninitialized state. The actual initialization needs to be performed by calling the async initialize() method or waiting for _initialize_engine_if_needed to run when required.
Source code in src/codemap/db/client.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
engine
instance-attribute
engine = None
initialized
instance-attribute
initialized = False
initialize
async
initialize() -> None
Asynchronously initialize the database client.
This should be called after creating the client and before using it.
Source code in src/codemap/db/client.py
46 47 48 49 50 51 52 53 54 55 |
|
cleanup
async
cleanup() -> None
Asynchronously cleanup the database client resources.
This should be called before discarding the client.
Source code in src/codemap/db/client.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
add_chat_message
add_chat_message(
session_id: str,
user_query: str,
ai_response: str | None = None,
context: str | None = None,
tool_calls: str | None = None,
) -> ChatHistory
Adds a chat message to the history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
str
|
The session identifier. |
required |
user_query
|
str
|
The user's query. |
required |
ai_response
|
Optional[str]
|
The AI's response. |
None
|
context
|
Optional[str]
|
JSON string of context used. |
None
|
tool_calls
|
Optional[str]
|
JSON string of tool calls made. |
None
|
Returns:
Name | Type | Description |
---|---|---|
ChatHistory |
ChatHistory
|
The newly created chat history record. |
Source code in src/codemap/db/client.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
get_chat_history
get_chat_history(
session_id: str, limit: int = 50
) -> list[ChatHistory]
Retrieves chat history for a session, ordered chronologically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
str
|
The session identifier. |
required |
limit
|
int
|
The maximum number of messages to return. |
50
|
Returns:
Type | Description |
---|---|
list[ChatHistory]
|
List[ChatHistory]: A list of chat history records. |
Source code in src/codemap/db/client.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
update_chat_response
update_chat_response(
message_id: int, ai_response: str
) -> bool
Updates the AI response for a specific chat message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message_id
|
int
|
The primary key ID of the chat message to update. |
required |
ai_response
|
str
|
The new AI response text. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the update was successful, False otherwise. |
Source code in src/codemap/db/client.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|