Skip to content

schema

schema

a class based approach for interacting with Domo Datasets

DomoDataset_Schema dataclass

DomoDataset_Schema(
    parent: DomoEntity,
    columns: list[DomoDataset_Schema_Column] = list(),
)

Bases: DomoSubEntity

class for interacting with dataset schemas

add_col async

add_col(
    col: DomoDataset_Schema_Column,
    debug_prn: bool = False,
    is_update_schema: bool = True,
    debug_api: bool = False,
    session: AsyncClient = None,
)

Add a column to the schema.

Source code in src/crew_dcs/classes/DomoDataset/schema.py
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
async def add_col(
    self,
    col: DomoDataset_Schema_Column,
    debug_prn: bool = False,
    is_update_schema: bool = True,
    debug_api: bool = False,
    session: httpx.AsyncClient = None,
):
    """Add a column to the schema."""
    if col in self.columns and debug_prn:
        await logger.debug(
            f"column - {col.name} already in dataset {self.parent.name if self.parent else ''}"
        )

    if col not in self.columns:
        self.columns.append(col)

    if not is_update_schema:
        return self.columns

    context = RouteContext.build_context(
        session=session,
        debug_api=debug_api,
    )
    return await self.update_schema(context=context)

get async

get(
    debug_api: bool = False,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoDataset_Schema_Column]

method that retrieves schema for a dataset

Calls route

Source code in src/crew_dcs/classes/DomoDataset/schema.py
 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
async def get(
    self,
    debug_api: bool = False,
    return_raw: bool = False,  # return the raw response
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoDataset_Schema_Column]:
    """method that retrieves schema for a dataset"""

    context = RouteContext.build_context(
        context=context,
        debug_api=debug_api,
        **context_kwargs,
    )

    res = await dataset_routes.get_schema(
        auth=self.auth, dataset_id=self.parent_id, context=context
    )

    self.raw = res.response

    if return_raw:
        return res

    self.columns = [
        DomoDataset_Schema_Column.from_dict(obj=obj)
        for obj in res.response.get("tables")[0].get("columns")
    ]

    return self.columns

remove_col async

remove_col(
    col_to_remove: DomoDataset_Schema_Column,
    debug_api: bool = False,
    is_update_schema: bool = True,
    session: AsyncClient = None,
)

Remove a column from the schema.

Source code in src/crew_dcs/classes/DomoDataset/schema.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
async def remove_col(
    self,
    col_to_remove: "DomoDataset_Schema_Column",
    debug_api: bool = False,
    is_update_schema: bool = True,
    session: httpx.AsyncClient = None,
):
    """Remove a column from the schema."""
    [
        self.columns.pop(index)
        for index, col in enumerate(self.columns)
        if col == col_to_remove
    ]

    if not is_update_schema:
        return self.columns

    context = RouteContext.build_context(
        session=session,
        debug_api=debug_api,
    )
    return await self.update_schema(context=context)

update_schema async

update_schema(
    return_raw: bool = False,
    session: AsyncClient = None,
    debug_api: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoDataset/schema.py
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
async def update_schema(
    self,
    return_raw: bool = False,
    session: httpx.AsyncClient = None,
    debug_api: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    dataset_id = self.parent.id
    auth = self.parent.auth

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    schema_obj = self.to_dict()

    res = await dataset_routes.alter_schema(
        dataset_id=dataset_id,
        auth=auth,
        schema_obj=schema_obj,
        context=context,
    )

    if return_raw:
        return res

    return await self.get(context=context)

update_schema_descriptions async

update_schema_descriptions(
    return_raw: bool = False,
    debug_api: bool = False,
    session: AsyncClient = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoDataset/schema.py
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
async def update_schema_descriptions(
    self,
    return_raw: bool = False,
    debug_api: bool = False,
    session: httpx.AsyncClient = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    dataset_id = self.parent.id
    auth = self.parent.auth

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    schema_obj = self.to_dict()

    if return_raw:
        return schema_obj

    await dataset_routes.alter_schema_descriptions(
        dataset_id=dataset_id,
        auth=auth,
        schema_obj=schema_obj,
        context=context,
    )

    return await self.get(context=context)