= '5e871f13-69d4-4012-8710-b61f654bb2b9'
DATASTORE_ID = 'd2b23a60-b1d3-4577-ac85-32ecc619708a'
COLLECTION_ID = '37948887-8ba3-4465-a749-c09518930229' DOCUMENT_ID
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)
= dmda.DomoTokenAuth(
auth =os.environ['DOMO_INSTANCE'],
domo_instance=os.environ["DOMO_ACCESS_TOKEN"],
domo_access_token
)
await AppDbDocument.get_by_id(
= auth,
auth = COLLECTION_ID,
collection_id= DOCUMENT_ID,
document_id= ['id'],
identity_columns= False
return_raw )
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)
= dmda.DomoTokenAuth(
auth =os.environ['DOMO_INSTANCE'],
domo_instance=os.environ["DOMO_ACCESS_TOKEN"],
domo_access_token
)= await AppDbDocument.get_by_id(
domo_doc = auth,
auth = COLLECTION_ID,
collection_id= DOCUMENT_ID,
document_id= ['id']
identity_columns
)
= {'update': 'update_via_content', 'id' : 12387 , "update_dt" : str(dt.date.today())}
content
await domo_doc.update_document(debug_api=False, content = content)).response (
warning 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'}}
'update': 'update via obj', 'update_dt' : dt.date.today()})
domo_doc.content.update({
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,
=None,
domo_user=None,
domo_group= appdb_routes.Collection_Permission_Enum.READ_CONTENT,
permission: appdb_routes.Collection_Permission_Enum bool = False,
debug_api: int = 2,
debug_num_stacks_to_drop: = None,
session: httpx.AsyncClient
):return await appdb_routes.modify_collection_permissions(
=self.id,
collection_id=(domo_user and domo_user.id) or (await self.auth.who_am_i()).response["id"],
user_id=domo_group and domo_group.id,
group_id=permission,
permission=self.auth,
auth=debug_api,
debug_api=debug_num_stacks_to_drop,
debug_num_stacks_to_drop=session,
session=self.__class__.__name__,
parent_class
)
@patch_to(AppDbCollection)
async def query_documents(
self,
dict = None,
query: bool = False,
return_raw: =False,
try_auto_sharebool = False,
debug_api: int = 2,
debug_num_stacks_to_drop: = None,
session: httpx.AsyncClient
):
= []
documents = 0
loop_retry while loop_retry <= 1 and not documents:
try:
= await appdb_routes.get_documents_from_collection(
res =self.auth,
auth=self.id,
collection_id=query,
query=debug_api,
debug_api=debug_num_stacks_to_drop,
debug_num_stacks_to_drop=session,
session
)
= res.response
documents
except appdb_routes.AppDb_GET_Exception as e:
if try_auto_share:
await self.share_collection(debug_api=debug_api)
await asyncio.sleep(2)
+= 1
loop_retry
if loop_retry > 1:
raise e
if return_raw:
return res
self.domo_documents = await ce.gather_with_concurrency(
*[
AppDbDocument.get_by_id(=self.id, document_id=doc["id"], auth=self.auth
collection_id
)for doc in documents
],=60
n
)
return self.domo_documents
CRUD 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 = ['id'],
identity_columns = {'update': 'testing_upsert', 'update_dt': '2024-06-28', 'id': 12387},
content = False
debug_api )
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
str = None
update := None
update_dt : dt.date str] = field(default_factory = ['id'])
_identity_columns : List[
def __post_init__(self):
self._identity_columns = ['id']
= dmda.DomoTokenAuth(
auth =os.environ['DOMO_INSTANCE'],
domo_instance=os.environ["DOMO_ACCESS_TOKEN"],
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 = ['id'],
identity_columns ={'update': 'upsert_via_class', 'id': 123, 'update_dt': '2024-06-28'}
content )
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 ()
= dmda.DomoTokenAuth(
auth =os.environ['DOMO_INSTANCE'],
domo_instance=os.environ["DOMO_ACCESS_TOKEN"],
domo_access_token
)
= await AppDbCollections.get_collections(auth = auth)
domo_collections 0:5] domo_collections[
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)]