python_arango_ogm.db.pao_db_base

  1from abc import ABC, abstractmethod
  2from typing import Any, Dict, Sequence
  3
  4
  5class PAODBBase(ABC):
  6    @abstractmethod
  7    def setup_app_database(self, delete_db):
  8        """
  9        Setup app databases; deleting if specified by delete_db
 10        This is called by constructor, but since this based on a
 11        Singleton metaclass, it might neccesary to call it manually
 12        after migrations have been appplied and whatnot.
 13        """
 14        pass
 15
 16    def get_related_edges(self, collection_name: str, association_collection_name: str, lookup_key_dict: Dict):
 17        """
 18        Gets `association_collection_name` edges of `collection_name`;
 19        looking up by the keys and values in `lookup_key_dict`:
 20        """
 21        pass
 22
 23    @abstractmethod
 24    def get_related_vertices(self, collection_name: str, association_collection_name: str, lookup_key_dict: Dict):
 25        """
 26        Lookup associated vertices (`association_collection_name`) through edges,
 27        from given collection_name, using keys and values in lookup_key_dict:
 28        """
 29        pass
 30
 31    @abstractmethod
 32    def inject_into_models(self):
 33        """ Inject database into models, as PAODatabase is where the functionality is implemented."""
 34        pass
 35
 36    @abstractmethod
 37    def get_db(self):
 38        """ Return underlying python-arango database"""
 39        pass
 40
 41    @abstractmethod
 42    def find_by_key(self, collection_name: str, key: Any):
 43        """
 44          Find document on collection by given key value:
 45        """
 46        pass
 47
 48    @abstractmethod
 49    def find_by_attributes(self, collection_name: str, lookup_key_dict: Dict = None):
 50        """
 51          Find a single document by given collection_name,
 52          looking up by the keys and values in lookup_key_dict:
 53        """
 54        pass
 55
 56    @abstractmethod
 57    def remove_by_key(self, collection_name: str, key: str):
 58        """ Remove a document identified by `key` from collection """
 59        pass
 60
 61    @abstractmethod
 62    def get_by_attributes(
 63            self,
 64            collection_name: str,
 65            lookup_key_dict: Dict = None,
 66            sort_key_dict: Dict[str, str] = None
 67    ):
 68        """
 69          Gets documents from given collection_name, looking up by the keys and values
 70          in lookup_key_dict, sorting by keys and direction
 71
 72          :param collection_name: Name of collection in Graph DB.
 73          :param lookup_key_dict: A dictionary of keys and corresponding values used to query this collection
 74          values (ASC, DESC):
 75          :param sort_key_dict: A dictionary of keys by which to sort documents.  Values specify direction (ASC, DESC, '')
 76        """
 77        pass
 78
 79    @abstractmethod
 80    def insert_edge(self, collection_name: str, association_collection_name: str, from_key, to_key):
 81        """
 82          Insert edge document using keys (_from and _to are generated using collection name).
 83          Collection inferred from collection_name and association_collection_name.
 84        """
 85        pass
 86
 87    @abstractmethod
 88    def insert_doc(self, collection_name: str, doc: Dict):
 89        """
 90          Insert a new doc in collection:
 91        """
 92        pass
 93
 94    @abstractmethod
 95    def insert_docs(self, collection_name: str, docs: Sequence[dict[str, Any]]):
 96        """ Insert given documents into collection with a single query"""
 97        pass
 98
 99    @abstractmethod
100    def upsert_doc(
101            self,
102            collection_name: str,
103            doc: Dict,
104            lookup_keys: Sequence[str] = None,
105            insert_dict=None,
106            update_dict=None
107    ):
108        """
109          Upsert a doc in collection using given lookup_keys
110          collection_name: Name of DB collection
111          doc:Dict: Document containing keys and values to insert and update
112          lookup_keys: Sequence of keys to lookup document to update
113          insert_dict: Dictionary of values to insert only
114          update_dict: Dictionary of values to update only
115        """
116        pass
class PAODBBase(abc.ABC):
  6class PAODBBase(ABC):
  7    @abstractmethod
  8    def setup_app_database(self, delete_db):
  9        """
 10        Setup app databases; deleting if specified by delete_db
 11        This is called by constructor, but since this based on a
 12        Singleton metaclass, it might neccesary to call it manually
 13        after migrations have been appplied and whatnot.
 14        """
 15        pass
 16
 17    def get_related_edges(self, collection_name: str, association_collection_name: str, lookup_key_dict: Dict):
 18        """
 19        Gets `association_collection_name` edges of `collection_name`;
 20        looking up by the keys and values in `lookup_key_dict`:
 21        """
 22        pass
 23
 24    @abstractmethod
 25    def get_related_vertices(self, collection_name: str, association_collection_name: str, lookup_key_dict: Dict):
 26        """
 27        Lookup associated vertices (`association_collection_name`) through edges,
 28        from given collection_name, using keys and values in lookup_key_dict:
 29        """
 30        pass
 31
 32    @abstractmethod
 33    def inject_into_models(self):
 34        """ Inject database into models, as PAODatabase is where the functionality is implemented."""
 35        pass
 36
 37    @abstractmethod
 38    def get_db(self):
 39        """ Return underlying python-arango database"""
 40        pass
 41
 42    @abstractmethod
 43    def find_by_key(self, collection_name: str, key: Any):
 44        """
 45          Find document on collection by given key value:
 46        """
 47        pass
 48
 49    @abstractmethod
 50    def find_by_attributes(self, collection_name: str, lookup_key_dict: Dict = None):
 51        """
 52          Find a single document by given collection_name,
 53          looking up by the keys and values in lookup_key_dict:
 54        """
 55        pass
 56
 57    @abstractmethod
 58    def remove_by_key(self, collection_name: str, key: str):
 59        """ Remove a document identified by `key` from collection """
 60        pass
 61
 62    @abstractmethod
 63    def get_by_attributes(
 64            self,
 65            collection_name: str,
 66            lookup_key_dict: Dict = None,
 67            sort_key_dict: Dict[str, str] = None
 68    ):
 69        """
 70          Gets documents from given collection_name, looking up by the keys and values
 71          in lookup_key_dict, sorting by keys and direction
 72
 73          :param collection_name: Name of collection in Graph DB.
 74          :param lookup_key_dict: A dictionary of keys and corresponding values used to query this collection
 75          values (ASC, DESC):
 76          :param sort_key_dict: A dictionary of keys by which to sort documents.  Values specify direction (ASC, DESC, '')
 77        """
 78        pass
 79
 80    @abstractmethod
 81    def insert_edge(self, collection_name: str, association_collection_name: str, from_key, to_key):
 82        """
 83          Insert edge document using keys (_from and _to are generated using collection name).
 84          Collection inferred from collection_name and association_collection_name.
 85        """
 86        pass
 87
 88    @abstractmethod
 89    def insert_doc(self, collection_name: str, doc: Dict):
 90        """
 91          Insert a new doc in collection:
 92        """
 93        pass
 94
 95    @abstractmethod
 96    def insert_docs(self, collection_name: str, docs: Sequence[dict[str, Any]]):
 97        """ Insert given documents into collection with a single query"""
 98        pass
 99
100    @abstractmethod
101    def upsert_doc(
102            self,
103            collection_name: str,
104            doc: Dict,
105            lookup_keys: Sequence[str] = None,
106            insert_dict=None,
107            update_dict=None
108    ):
109        """
110          Upsert a doc in collection using given lookup_keys
111          collection_name: Name of DB collection
112          doc:Dict: Document containing keys and values to insert and update
113          lookup_keys: Sequence of keys to lookup document to update
114          insert_dict: Dictionary of values to insert only
115          update_dict: Dictionary of values to update only
116        """
117        pass

Helper class that provides a standard way to create an ABC using inheritance.

@abstractmethod
def setup_app_database(self, delete_db):
 7    @abstractmethod
 8    def setup_app_database(self, delete_db):
 9        """
10        Setup app databases; deleting if specified by delete_db
11        This is called by constructor, but since this based on a
12        Singleton metaclass, it might neccesary to call it manually
13        after migrations have been appplied and whatnot.
14        """
15        pass

Setup app databases; deleting if specified by delete_db This is called by constructor, but since this based on a Singleton metaclass, it might neccesary to call it manually after migrations have been appplied and whatnot.

@abstractmethod
def inject_into_models(self):
32    @abstractmethod
33    def inject_into_models(self):
34        """ Inject database into models, as PAODatabase is where the functionality is implemented."""
35        pass

Inject database into models, as PAODatabase is where the functionality is implemented.

@abstractmethod
def get_db(self):
37    @abstractmethod
38    def get_db(self):
39        """ Return underlying python-arango database"""
40        pass

Return underlying python-arango database

@abstractmethod
def find_by_key(self, collection_name: str, key: Any):
42    @abstractmethod
43    def find_by_key(self, collection_name: str, key: Any):
44        """
45          Find document on collection by given key value:
46        """
47        pass

Find document on collection by given key value:

@abstractmethod
def find_by_attributes(self, collection_name: str, lookup_key_dict: Dict = None):
49    @abstractmethod
50    def find_by_attributes(self, collection_name: str, lookup_key_dict: Dict = None):
51        """
52          Find a single document by given collection_name,
53          looking up by the keys and values in lookup_key_dict:
54        """
55        pass

Find a single document by given collection_name, looking up by the keys and values in lookup_key_dict:

@abstractmethod
def remove_by_key(self, collection_name: str, key: str):
57    @abstractmethod
58    def remove_by_key(self, collection_name: str, key: str):
59        """ Remove a document identified by `key` from collection """
60        pass

Remove a document identified by key from collection

@abstractmethod
def get_by_attributes( self, collection_name: str, lookup_key_dict: Dict = None, sort_key_dict: Dict[str, str] = None):
62    @abstractmethod
63    def get_by_attributes(
64            self,
65            collection_name: str,
66            lookup_key_dict: Dict = None,
67            sort_key_dict: Dict[str, str] = None
68    ):
69        """
70          Gets documents from given collection_name, looking up by the keys and values
71          in lookup_key_dict, sorting by keys and direction
72
73          :param collection_name: Name of collection in Graph DB.
74          :param lookup_key_dict: A dictionary of keys and corresponding values used to query this collection
75          values (ASC, DESC):
76          :param sort_key_dict: A dictionary of keys by which to sort documents.  Values specify direction (ASC, DESC, '')
77        """
78        pass

Gets documents from given collection_name, looking up by the keys and values in lookup_key_dict, sorting by keys and direction

Parameters
  • collection_name: Name of collection in Graph DB.
  • lookup_key_dict: A dictionary of keys and corresponding values used to query this collection values (ASC, DESC):
  • sort_key_dict: A dictionary of keys by which to sort documents. Values specify direction (ASC, DESC, '')
@abstractmethod
def insert_edge( self, collection_name: str, association_collection_name: str, from_key, to_key):
80    @abstractmethod
81    def insert_edge(self, collection_name: str, association_collection_name: str, from_key, to_key):
82        """
83          Insert edge document using keys (_from and _to are generated using collection name).
84          Collection inferred from collection_name and association_collection_name.
85        """
86        pass

Insert edge document using keys (_from and _to are generated using collection name). Collection inferred from collection_name and association_collection_name.

@abstractmethod
def insert_doc(self, collection_name: str, doc: Dict):
88    @abstractmethod
89    def insert_doc(self, collection_name: str, doc: Dict):
90        """
91          Insert a new doc in collection:
92        """
93        pass

Insert a new doc in collection:

@abstractmethod
def insert_docs(self, collection_name: str, docs: Sequence[dict[str, Any]]):
95    @abstractmethod
96    def insert_docs(self, collection_name: str, docs: Sequence[dict[str, Any]]):
97        """ Insert given documents into collection with a single query"""
98        pass

Insert given documents into collection with a single query

@abstractmethod
def upsert_doc( self, collection_name: str, doc: Dict, lookup_keys: Sequence[str] = None, insert_dict=None, update_dict=None):
100    @abstractmethod
101    def upsert_doc(
102            self,
103            collection_name: str,
104            doc: Dict,
105            lookup_keys: Sequence[str] = None,
106            insert_dict=None,
107            update_dict=None
108    ):
109        """
110          Upsert a doc in collection using given lookup_keys
111          collection_name: Name of DB collection
112          doc:Dict: Document containing keys and values to insert and update
113          lookup_keys: Sequence of keys to lookup document to update
114          insert_dict: Dictionary of values to insert only
115          update_dict: Dictionary of values to update only
116        """
117        pass

Upsert a doc in collection using given lookup_keys collection_name: Name of DB collection doc:Dict: Document containing keys and values to insert and update lookup_keys: Sequence of keys to lookup document to update insert_dict: Dictionary of values to insert only update_dict: Dictionary of values to update only