|
5 | 5 |
|
6 | 6 | import json
|
7 | 7 | from enum import Enum
|
8 |
| -from typing import TYPE_CHECKING, Dict, List, Optional, Union |
| 8 | +from typing import TYPE_CHECKING, AsyncGenerator, Dict, Generator, List, Optional, Union |
9 | 9 |
|
10 | 10 | from synapseclient.core.utils import delete_none_keys, id_of
|
11 | 11 |
|
@@ -123,6 +123,97 @@ async def get_columns(
|
123 | 123 | return columns
|
124 | 124 |
|
125 | 125 |
|
| 126 | +async def get_column( |
| 127 | + column_id: str, |
| 128 | + *, |
| 129 | + synapse_client: Optional["Synapse"] = None, |
| 130 | +) -> Dict[str, Union[str, int]]: |
| 131 | + """Get a single column by ID. |
| 132 | +
|
| 133 | + Arguments: |
| 134 | + column_id: The ID of the column to retrieve. |
| 135 | + synapse_client: If not passed in and caching was not disabled by |
| 136 | + `Synapse.allow_client_caching(False)` this will use the last created |
| 137 | + instance from the Synapse class constructor. |
| 138 | +
|
| 139 | + Returns: |
| 140 | + The column matching <https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/table/ColumnModel.html> |
| 141 | + """ |
| 142 | + from synapseclient import Synapse |
| 143 | + |
| 144 | + return await Synapse.get_client(synapse_client=synapse_client).rest_get_async( |
| 145 | + f"/column/{column_id}", |
| 146 | + ) |
| 147 | + |
| 148 | + |
| 149 | +async def list_columns( |
| 150 | + prefix: Optional[str] = None, |
| 151 | + limit: int = 100, |
| 152 | + offset: int = 0, |
| 153 | + *, |
| 154 | + synapse_client: Optional["Synapse"] = None, |
| 155 | +) -> AsyncGenerator["Column", None]: |
| 156 | + """List columns with optional prefix filtering. |
| 157 | +
|
| 158 | + Arguments: |
| 159 | + prefix: Optional prefix to filter columns by name. |
| 160 | + limit: Number of columns to retrieve per request to Synapse (pagination parameter). |
| 161 | + The function will continue retrieving results until all matching columns are returned. |
| 162 | + offset: The index of the first column to return (pagination parameter). |
| 163 | + synapse_client: If not passed in and caching was not disabled by |
| 164 | + `Synapse.allow_client_caching(False)` this will use the last created |
| 165 | + instance from the Synapse class constructor. |
| 166 | +
|
| 167 | + Yields: Column instances. |
| 168 | + """ |
| 169 | + from synapseclient.api.api_client import rest_get_paginated_async |
| 170 | + from synapseclient.models import Column |
| 171 | + |
| 172 | + if prefix is None: |
| 173 | + uri = "/column" |
| 174 | + else: |
| 175 | + uri = f"/column?prefix={prefix}" |
| 176 | + |
| 177 | + async for result in rest_get_paginated_async( |
| 178 | + uri, limit=limit, offset=offset, synapse_client=synapse_client |
| 179 | + ): |
| 180 | + yield Column().fill_from_dict(synapse_column=result) |
| 181 | + |
| 182 | + |
| 183 | +def list_columns_sync( |
| 184 | + prefix: Optional[str] = None, |
| 185 | + limit: int = 100, |
| 186 | + offset: int = 0, |
| 187 | + *, |
| 188 | + synapse_client: Optional["Synapse"] = None, |
| 189 | +) -> Generator["Column", None, None]: |
| 190 | + """List columns with optional prefix filtering (synchronous version). |
| 191 | +
|
| 192 | + Arguments: |
| 193 | + prefix: Optional prefix to filter columns by name. |
| 194 | + limit: Number of columns to retrieve per request to Synapse (pagination parameter). |
| 195 | + The function will continue retrieving results until all matching columns are returned. |
| 196 | + offset: The index of the first column to return (pagination parameter). |
| 197 | + synapse_client: If not passed in and caching was not disabled by |
| 198 | + `Synapse.allow_client_caching(False)` this will use the last created |
| 199 | + instance from the Synapse class constructor. |
| 200 | +
|
| 201 | + Yields: Column instances. |
| 202 | + """ |
| 203 | + from synapseclient import Synapse |
| 204 | + from synapseclient.models import Column |
| 205 | + |
| 206 | + client = Synapse.get_client(synapse_client=synapse_client) |
| 207 | + |
| 208 | + if prefix is None: |
| 209 | + uri = "/column" |
| 210 | + else: |
| 211 | + uri = f"/column?prefix={prefix}" |
| 212 | + |
| 213 | + for result in client._GET_paginated(uri, limit=limit, offset=offset): |
| 214 | + yield Column().fill_from_dict(synapse_column=result) |
| 215 | + |
| 216 | + |
126 | 217 | async def post_columns(
|
127 | 218 | columns: List["Column"], *, synapse_client: Optional["Synapse"] = None
|
128 | 219 | ) -> List["Column"]:
|
|
0 commit comments