DATASTORE_ID = '5e871f13-69d4-4012-8710-b61f654bb2b9'
COLLECTION_ID = 'd2b23a60-b1d3-4577-ac85-32ecc619708a'
DOCUMENT_ID = '37948887-8ba3-4465-a749-c09518930229'AppDb
a class based approach for interacting with appdb
AppDbDocument
AppDbDocument
AppDbDocument (auth:domolibrary.client.DomoAuth.DomoAuth, _collection_id:str, _identity_columns:List[str], _id:str=None, _created_on_dt:datetime.datetime=None, _updated_on_dt:datetime.datetime=None, content:dict=None)
to_json
to_json (value)
auth = dmda.DomoTokenAuth(
domo_instance=os.environ['DOMO_INSTANCE'],
domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
)
await AppDbDocument.get_by_id(
auth = auth,
collection_id= COLLECTION_ID,
document_id= DOCUMENT_ID,
identity_columns= ['id'],
return_raw= False
)warning this token has not been validated by who_am_i, run get_auth_token first
AppDbDocument(_collection_id='d2b23a60-b1d3-4577-ac85-32ecc619708a', _identity_columns=['id'], _id='37948887-8ba3-4465-a749-c09518930229', _created_on_dt=datetime.datetime(2024, 6, 28, 15, 30, 19, 818000, tzinfo=tzutc()), _updated_on_dt=datetime.datetime(2024, 8, 12, 20, 8, 25, 995000, tzinfo=tzutc()), content={'update': 'testing_upsert', 'update_dt': '2024-06-28', 'id': 12387})
CRUD Document
AppDbDocument.update_document
AppDbDocument.update_document (content:dict=None, debug_api:bool=False, session:httpx.AsyncClient=None, debug_num_stacks_to_drop=1, return_raw:bool=False)
auth = dmda.DomoTokenAuth(
domo_instance=os.environ['DOMO_INSTANCE'],
domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
)
domo_doc = await AppDbDocument.get_by_id(
auth = auth,
collection_id= COLLECTION_ID,
document_id= DOCUMENT_ID,
identity_columns= ['id']
)
content = {'update': 'update_via_content', 'id' : 12387 , "update_dt" : str(dt.date.today())}
(await domo_doc.update_document(debug_api=False, content = content)).responsewarning this token has not been validated by who_am_i, run get_auth_token first
{'id': '37948887-8ba3-4465-a749-c09518930229',
'datastoreId': '5e871f13-69d4-4012-8710-b61f654bb2b9',
'collectionId': 'd2b23a60-b1d3-4577-ac85-32ecc619708a',
'syncRequired': True,
'owner': '1893952720',
'createdBy': '1893952720',
'createdOn': '2024-06-28T15:30:19.818Z',
'updatedOn': '2024-08-12T20:57:57.995Z',
'updatedBy': '1893952720',
'content': {'update': 'update_via_content',
'id': 12387,
'update_dt': '2024-08-12'}}
domo_doc.content.update({ 'update': 'update via obj', 'update_dt' : dt.date.today()})
(await domo_doc.update_document(debug_api=False)).response{'id': '37948887-8ba3-4465-a749-c09518930229',
'datastoreId': '5e871f13-69d4-4012-8710-b61f654bb2b9',
'collectionId': 'd2b23a60-b1d3-4577-ac85-32ecc619708a',
'syncRequired': True,
'owner': '1893952720',
'createdBy': '1893952720',
'createdOn': '2024-06-28T15:30:19.818Z',
'updatedOn': '2024-08-12T20:57:58.346Z',
'updatedBy': '1893952720',
'content': {'update': 'update_via_content',
'id': 12387,
'update_dt': '2024-08-12'}}
sample Custom Document (with schema)
AppDbCollection
AppDbCollection
AppDbCollection (auth:domolibrary.client.DomoAuth.DomoAuth, id:str, name:str, created_on_dt:datetime.datetime, updated_on_dt:datetime.datetime, schema:dict, domo_documents:List[__main__.AppDbDocument]=None)
AppDbCollection.query_documents
AppDbCollection.query_documents (query:dict=None, return_raw:bool=False, try_auto_share=False, debug_api:bool=False, debug_num_stacks_to_drop:int=2, session:httpx.AsyncClient=None)
Exported source
@patch_to(AppDbCollection)
async def share_collection(
self,
domo_user=None,
domo_group=None,
permission: appdb_routes.Collection_Permission_Enum = appdb_routes.Collection_Permission_Enum.READ_CONTENT,
debug_api: bool = False,
debug_num_stacks_to_drop: int = 2,
session: httpx.AsyncClient = None,
):
return await appdb_routes.modify_collection_permissions(
collection_id=self.id,
user_id=(domo_user and domo_user.id) or (await self.auth.who_am_i()).response["id"],
group_id=domo_group and domo_group.id,
permission=permission,
auth=self.auth,
debug_api=debug_api,
debug_num_stacks_to_drop=debug_num_stacks_to_drop,
session=session,
parent_class=self.__class__.__name__,
)
@patch_to(AppDbCollection)
async def query_documents(
self,
query: dict = None,
return_raw: bool = False,
try_auto_share=False,
debug_api: bool = False,
debug_num_stacks_to_drop: int = 2,
session: httpx.AsyncClient = None,
):
documents = []
loop_retry = 0
while loop_retry <= 1 and not documents:
try:
res = await appdb_routes.get_documents_from_collection(
auth=self.auth,
collection_id=self.id,
query=query,
debug_api=debug_api,
debug_num_stacks_to_drop=debug_num_stacks_to_drop,
session=session,
)
documents = res.response
except appdb_routes.AppDb_GET_Exception as e:
if try_auto_share:
await self.share_collection(debug_api=debug_api)
await asyncio.sleep(2)
loop_retry += 1
if loop_retry > 1:
raise e
if return_raw:
return res
self.domo_documents = await ce.gather_with_concurrency(
*[
AppDbDocument.get_by_id(
collection_id=self.id, document_id=doc["id"], auth=self.auth
)
for doc in documents
],
n=60
)
return self.domo_documentsCRUD Document pt 2
UPSERT Document
AppDbDocument.upsert
AppDbDocument.upsert (auth:domolibrary.client.DomoAuth.DomoAuth, collection_id, content:dict, identity_columns:List[str], session:httpx.AsyncClient=None, debug_api=False, debug_num_stacks_to_drop=3, return_raw:bool=False)
await AppDbDocument.upsert(
auth = auth,
collection_id = COLLECTION_ID,
identity_columns = ['id'],
content = {'update': 'testing_upsert', 'update_dt': '2024-06-28', 'id': 12387},
debug_api = False
)ResponseGetData(status=200, response={'id': '37948887-8ba3-4465-a749-c09518930229', 'datastoreId': '5e871f13-69d4-4012-8710-b61f654bb2b9', 'collectionId': 'd2b23a60-b1d3-4577-ac85-32ecc619708a', 'syncRequired': True, 'owner': '1893952720', 'createdBy': '1893952720', 'createdOn': '2024-06-28T15:30:19.818Z', 'updatedOn': '2024-08-12T20:58:02.358Z', 'updatedBy': '1893952720', 'content': {'update': 'testing_upsert', 'update_dt': '2024-06-28', 'id': 12387}}, is_success=True, parent_class=None)
@dataclass
class TestDoc(AppDbDocument):
id : int = None
update :str = None
update_dt : dt.date = None
_identity_columns : List[str] = field(default_factory = ['id'])
def __post_init__(self):
self._identity_columns = ['id']
auth = dmda.DomoTokenAuth(
domo_instance=os.environ['DOMO_INSTANCE'],
domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
)
await TestDoc.get_by_id(collection_id= COLLECTION_ID,
document_id= DOCUMENT_ID,
auth = auth)
await TestDoc.upsert(
auth = auth,
collection_id = COLLECTION_ID,
identity_columns = ['id'],
content={'update': 'upsert_via_class', 'id': 123, 'update_dt': '2024-06-28'}
)warning this token has not been validated by who_am_i, run get_auth_token first
ResponseGetData(status=200, response={'id': '33857249-515b-4659-9779-b85f82675677', 'datastoreId': '5e871f13-69d4-4012-8710-b61f654bb2b9', 'collectionId': 'd2b23a60-b1d3-4577-ac85-32ecc619708a', 'syncRequired': True, 'owner': '1893952720', 'createdBy': '1893952720', 'createdOn': '2024-06-28T19:33:52.179Z', 'updatedOn': '2024-08-12T20:58:04.275Z', 'updatedBy': '1893952720', 'content': {'update': 'upsert_via_class', 'id': 123, 'update_dt': '2024-06-28'}}, is_success=True, parent_class=None)
AppDbCollections
AppDbCollections
AppDbCollections ()
auth = dmda.DomoTokenAuth(
domo_instance=os.environ['DOMO_INSTANCE'],
domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
)
domo_collections = await AppDbCollections.get_collections(auth = auth)
domo_collections[0:5]warning this token has not been validated by who_am_i, run get_auth_token first
[AppDbCollection(id='3e6ba7a6-9261-44fd-8eef-987fdbb99e18', name='ColumnConfig', created_on_dt=datetime.datetime(2020, 11, 20, 17, 58, 42, 550000, tzinfo=tzutc()), updated_on_dt=datetime.datetime(2023, 2, 14, 20, 17, 27, 920000, tzinfo=tzutc()), schema=None, domo_documents=None),
AppDbCollection(id='7464cb2b-1905-4e10-b1f3-52e013394c41', name='DatasetSettings', created_on_dt=datetime.datetime(2020, 11, 20, 17, 58, 42, 667000, tzinfo=tzutc()), updated_on_dt=datetime.datetime(2023, 2, 14, 20, 17, 27, 920000, tzinfo=tzutc()), schema=None, domo_documents=None),
AppDbCollection(id='4dec4d72-ca45-4d19-9c7e-fbdd148f7ff2', name='AppSettings', created_on_dt=datetime.datetime(2020, 11, 20, 17, 58, 42, 797000, tzinfo=tzutc()), updated_on_dt=datetime.datetime(2023, 2, 14, 20, 17, 27, 920000, tzinfo=tzutc()), schema=None, domo_documents=None),
AppDbCollection(id='64ce5832-6a91-4892-a456-b09106949629', name='TemplatesAndForms', created_on_dt=datetime.datetime(2021, 3, 31, 18, 11, 13, 260000, tzinfo=tzutc()), updated_on_dt=datetime.datetime(2023, 2, 14, 20, 17, 27, 920000, tzinfo=tzutc()), schema=None, domo_documents=None),
AppDbCollection(id='e09f2670-a3e6-4888-a070-c7c97953c4cd', name='UserSettings', created_on_dt=datetime.datetime(2021, 3, 31, 18, 11, 13, 413000, tzinfo=tzutc()), updated_on_dt=datetime.datetime(2023, 2, 14, 20, 17, 27, 920000, tzinfo=tzutc()), schema=None, domo_documents=None)]