From b45077950bbeb59ba97f701899ab3ec6ebbf6d9c Mon Sep 17 00:00:00 2001 From: lasseedfast <> Date: Mon, 6 May 2024 07:45:43 +0200 Subject: [PATCH] Add get_persons method to ArangoDB class --- _arango.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/_arango.py b/_arango.py index b1be878..2a9e79d 100644 --- a/_arango.py +++ b/_arango.py @@ -41,6 +41,34 @@ class ArangoDB: if len(encoded_string) > 254: string = encoded_string[:254].decode('utf-8', 'ignore') return string + + def get_persons(self, confirmed=True): + """ + Gets a list of all names in the database. + + Args: + confirmed (bool, optional): If True, only returns names of confirmed persons. + If False, returns names of all persons. + Defaults to True. + + Returns: + dict: A dictionary containing two lists: + - 'names': A list of all names in the database. + - 'dict_persons': A list of dictionaries, where each dictionary contains the name and key of a person. + """ + confirmed_string = '' + if confirmed: + confirmed_string = 'filter person.confirmed == true' + + query = f""" + FOR person IN persons + {confirmed_string} + RETURN {{'name': person.name, '_key': person._key}} + """ + persons = [i for i in self.db.aql.execute(query)] + names = [document['name'] for document in persons] + dict_persons = {document['name']: document['_key'] for document in persons} + return {'names': names, 'dict':dict_persons} arango = ArangoDB()