infrastructure.persistence.repositories.provider_connection_repository¶
src.infrastructure.persistence.repositories.provider_connection_repository
¶
ProviderConnectionRepository - SQLAlchemy implementation.
Adapter for hexagonal architecture. Maps between domain ProviderConnection entities and database ProviderConnectionModel.
Reference
- docs/architecture/repository-pattern.md
Classes¶
ProviderConnectionRepository
¶
SQLAlchemy implementation of ProviderConnectionRepository protocol.
This is an adapter that implements the ProviderConnectionRepository port. It handles the mapping between domain ProviderConnection entities and database ProviderConnectionModel.
This class does NOT inherit from the protocol (Protocol uses structural typing).
Attributes:
| Name | Type | Description |
|---|---|---|
session |
SQLAlchemy async session for database operations. |
Example
async with get_session() as session: ... repo = ProviderConnectionRepository(session) ... conn = await repo.find_by_id(connection_id)
Source code in src/infrastructure/persistence/repositories/provider_connection_repository.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
Functions¶
__init__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AsyncSession
|
SQLAlchemy async session. |
required |
find_by_id
async
¶
Find connection by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_id
|
UUID
|
Connection's unique identifier. |
required |
Returns:
| Type | Description |
|---|---|
ProviderConnection | None
|
Domain ProviderConnection entity if found, None otherwise. |
Source code in src/infrastructure/persistence/repositories/provider_connection_repository.py
find_by_user_id
async
¶
Find all connections for a user.
Returns connections in all statuses (including disconnected).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
UUID
|
User's unique identifier. |
required |
Returns:
| Type | Description |
|---|---|
list[ProviderConnection]
|
List of connections (empty if none found). |
Source code in src/infrastructure/persistence/repositories/provider_connection_repository.py
find_by_user_and_provider
async
¶
Find all connections for user + provider combination.
User may have multiple connections to same provider (different accounts).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
UUID
|
User's unique identifier. |
required |
provider_id
|
UUID
|
Provider's unique identifier. |
required |
Returns:
| Type | Description |
|---|---|
list[ProviderConnection]
|
List of connections (empty if none found). |
Source code in src/infrastructure/persistence/repositories/provider_connection_repository.py
find_active_by_user
async
¶
Find all active connections for a user.
Only returns connections with status=ACTIVE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
UUID
|
User's unique identifier. |
required |
Returns:
| Type | Description |
|---|---|
list[ProviderConnection]
|
List of active connections (empty if none found). |
Source code in src/infrastructure/persistence/repositories/provider_connection_repository.py
save
async
¶
Create or update connection in database.
Uses merge semantics - creates if not exists, updates if exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
ProviderConnection
|
ProviderConnection entity to persist. |
required |
Source code in src/infrastructure/persistence/repositories/provider_connection_repository.py
delete
async
¶
Remove connection from database.
Hard delete - permanently removes the record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_id
|
UUID
|
Connection's unique identifier. |
required |
Raises:
| Type | Description |
|---|---|
NoResultFound
|
If connection doesn't exist. |
Source code in src/infrastructure/persistence/repositories/provider_connection_repository.py
find_expiring_soon
async
¶
Find connections with credentials expiring soon.
Used by background job to proactively refresh credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minutes
|
int
|
Time threshold in minutes (default 30). |
30
|
Returns:
| Type | Description |
|---|---|
list[ProviderConnection]
|
List of active connections with credentials expiring within threshold. |