connections
Connections.
This module contains the database connection and operations for the tool inventory application. It includes classes for handling database operations and custom exceptions for error handling.
Database
¶
Database connection.
Source code in src/tool_inventory/connections.py
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 | |
__init__
¶
Initialize database connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The database session. |
required |
create_tool
¶
Create a tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
Tool
|
The tool to create. |
required |
Returns:
| Type | Description |
|---|---|
Tool
|
The created tool. |
Raises:
| Type | Description |
|---|---|
ToolExistsError
|
If the tool already exists. |
Source code in src/tool_inventory/connections.py
delete_tool
¶
Delete a tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_id
|
UUID
|
The UUID of the tool to delete. |
required |
Raises:
| Type | Description |
|---|---|
ToolNotFoundError
|
If the tool is not found. |
Source code in src/tool_inventory/connections.py
get_tool_by_id
¶
Get a tool by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_id
|
UUID
|
The UUID of the tool. |
required |
Returns:
| Type | Description |
|---|---|
Tool
|
The tool with the specified ID. |
Raises:
| Type | Description |
|---|---|
ToolNotFoundError
|
If the tool is not found. |
Source code in src/tool_inventory/connections.py
get_tools
¶
Get tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the tool to filter by. |
None
|
Returns:
| Type | Description |
|---|---|
list[Tool]
|
A list of tools. |
Source code in src/tool_inventory/connections.py
search_tools
¶
Search tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The search query. |
required |
Returns:
| Type | Description |
|---|---|
list[Tool]
|
A list of tools. |
Source code in src/tool_inventory/connections.py
update_tool
¶
Update a tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
Tool
|
The tool to update. |
required |
Returns:
| Type | Description |
|---|---|
Tool
|
The updated tool. |
Raises:
| Type | Description |
|---|---|
ToolNotFoundError
|
If the tool is not found. |
Source code in src/tool_inventory/connections.py
ObjectExistsError
¶
Bases: Exception
Object exists error.
Source code in src/tool_inventory/connections.py
__init__
¶
Initialize object exists error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_id
|
UUID
|
The UUID of the object. |
required |
ObjectNotFoundError
¶
Bases: Exception
Object not found error.
Source code in src/tool_inventory/connections.py
__init__
¶
Initialize object not found error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_id
|
UUID
|
The UUID of the object. |
required |
ToolExistsError
¶
Bases: ObjectExistsError
Tool exists error.
Source code in src/tool_inventory/connections.py
__init__
¶
Initialize tool exists error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_id
|
UUID
|
The UUID of the tool. |
required |
ToolNotFoundError
¶
Bases: ObjectNotFoundError
Tool not found error.
Source code in src/tool_inventory/connections.py
__init__
¶
Initialize tool not found error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_id
|
UUID
|
The UUID of the tool. |
required |