From f8437486db9023fe97cc02475929f505a72a33e4 Mon Sep 17 00:00:00 2001 From: Michael Fekadu Date: Tue, 14 Jan 2020 11:28:08 -0800 Subject: [PATCH] nice docs --- NimbusDatabase/__init__.py | 0 .../database_wrapper.py | 2 +- doc/NimbusDatabase/database_wrapper.html | 1114 +++++++++++++++++ doc/NimbusDatabase/index.html | 60 + 4 files changed, 1175 insertions(+), 1 deletion(-) create mode 100644 NimbusDatabase/__init__.py rename database_wrapper.py => NimbusDatabase/database_wrapper.py (99%) create mode 100644 doc/NimbusDatabase/database_wrapper.html create mode 100644 doc/NimbusDatabase/index.html diff --git a/NimbusDatabase/__init__.py b/NimbusDatabase/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/database_wrapper.py b/NimbusDatabase/database_wrapper.py similarity index 99% rename from database_wrapper.py rename to NimbusDatabase/database_wrapper.py index 3bd4bca..c2f25b5 100644 --- a/database_wrapper.py +++ b/NimbusDatabase/database_wrapper.py @@ -11,7 +11,7 @@ #!/usr/bin/env python3 import mysql.connector from abc import ABC, abstractmethod -from typing import Any, Optional +from typing import Any, Optional, List import json diff --git a/doc/NimbusDatabase/database_wrapper.html b/doc/NimbusDatabase/database_wrapper.html new file mode 100644 index 0000000..5293a1f --- /dev/null +++ b/doc/NimbusDatabase/database_wrapper.html @@ -0,0 +1,1114 @@ + + + + + + +NimbusDatabase.database_wrapper API documentation + + + + + + + + + +
+
+
+

Module NimbusDatabase.database_wrapper

+
+
+

A wrapper module for the Nimbus data storage systems.

+

This module includes various adapters for interfacing with +different databases and storage locations.

+
Typical usage example:
+
+db = NimbusMySQL(config_file="config.json")
+ents = db.get_entities()
+
+
+ +Expand source code + +
"""A wrapper module for the Nimbus data storage systems.
+
+This module includes various adapters for interfacing with
+different databases and storage locations.
+
+    Typical usage example:
+
+    db = NimbusMySQL(config_file="config.json")
+    ents = db.get_entities()
+"""
+#!/usr/bin/env python3
+import mysql.connector
+from abc import ABC, abstractmethod
+from typing import Any, Optional, List
+import json
+
+
+class UnsupportedDatabaseError(Exception):
+    """Raised when operation tries to connect to an unsupported database type.
+
+    Attributes:
+        message: an explanation of why the expected database is unsupported.
+    """
+
+    def __init__(self, message: str):
+        self.message = message
+
+
+class BadConfigFileError(Exception):
+    """Raised when the config.json file is badly formatter (e.g missing field).
+
+    Attributes:
+        message: an explanation.
+    """
+
+    def __init__(self, message: str):
+        self.message = message
+
+
+        
+        
+"""
+utilities.py
+"""
+def get_current_time():
+    """
+    Useful for answering questions like "Is prof availible now/tomorrow?"
+    """
+    pass
+        
+
+class NimbusDatabase(ABC):
+    """
+    An abstract class for interacting with the Nimbus database.
+    Concrete subclasses, such as NimbusMySQL,
+    should implement these operations such as `connect`
+    """
+
+    def __init__(self, config_file: str = 'config.json') -> None:
+        """
+        Inits Nimbus Database using the hostname, username, password
+        found inside the config_file.
+        """
+        pass
+
+    
+    @abstractmethod
+    def get_property_from_entity(self, 
+                                 prop: List[str],
+                                 entity: str, 
+                                 condition_field: Optional[str] = None,
+                                 condition_value: Optional[str] = None) -> List[str]:
+        """A higher-order function to get properties from entity in the database.
+
+        Example:
+        >>> db = NimbusDatabase("config.json")
+        >>> db.get_property_from_entity(["firstName", "lastName"], "Professors")
+        [("Foaad", "Khosmood"), ("John", "Clements"), ...]
+
+        >>> db.get_property_from_entity(["firstName", "lastName"], "Professors", "firstName", "Foaad")
+        [("Foaad", "Khosmood")]
+
+        Args:
+            entity: a string representing a table in the database.
+            prop: string(s) representing a field in the given table.
+            condition_field: (optional) string representing the column name.
+            condition_value: (optional) string representing the cell value.
+
+        Returns:
+            The list of prop of the entity (e.g. firstName of Professor)
+        """
+        pass
+
+    @abstractmethod
+    def get_property_from_related_entities(self,
+                                           prop: List[str],
+                                           entity1: str,
+                                           entity2: str,
+                                           key1: str, 
+                                           key2: Optional[str] = None,
+                                           condition_field: Optional[str] = None,
+                                           condition_value: Optional[str] = None) -> List[str]:
+        """A higher-order function to ????
+
+        Example:
+        >>> db = NimbusDatabase("config.json")
+        >>> db.get_property_from_related_entities(["firstName", "lastName", "ohRoom"], "Professors", "OfficeHours", "professorId")
+        [("Foaad", "Khosmood", "14-213"), ("John", "Clements", "14-210"), ...]
+
+        >>> db.get_property_from_related_entities(["firstName", "lastName"], "Professors", "OfficeHours", "professorId", "firstName", "Foaad")
+        [("Foaad", "Khosmood", "14-213")]
+
+        Args:
+            entity: TODO
+            prop: TODO
+
+        Returns:
+            TODO
+        """
+        pass
+        
+    
+    @abstractmethod
+    def get_entities(self) -> str:
+        pass
+
+
+    @abstractmethod
+    def get_fields_of_entity(self, entity1: str) -> str:
+        """
+        TODO: given an entity, return all the field names of that table in the database. 
+        """
+        pass
+
+    @abstractmethod
+    def get_unique(self, entity) -> str:
+        pass
+
+    @abstractmethod
+    def get_bitcount(self, entity) -> str:
+        pass
+
+    @abstractmethod
+    def close(self) -> None:
+        """
+        Simple Implementation Example:
+        ```
+        self.connection.close()
+        super().close()
+        ```
+        """
+        print("database connection was closed.")
+        pass
+
+    def __del__(self) -> None:
+        """
+        This method can make sure that the database connection is closed
+        before garbage references are collected.
+
+        There are reasons to not use `__del__`:
+        https://stackoverflow.com/q/1481488
+
+        Example:
+            >>> import database_wrapper
+            >>> db = database_wrapper.NimbusMySQL()
+            >>> del db
+            database object is being garbage collected...
+            database connection was closed.
+        """
+        print("database object is being garbage collected...")
+        self.close()
+        return
+
+
+class NimbusMySQL(NimbusDatabase):
+    """An adapter for mysql-connector-python to fit our program.
+
+    The NimbusMySQL makes the mysql-connector-python interface
+    compatible with the our program's interface.
+
+    Attributes:
+        config_file: a JSON file with the mysql details.
+    """
+
+    def __init__(self, config_file: str = 'config.json') -> None:
+        """
+        Inits Nimbus Database using the hostname, username, password
+        found inside the config_file.
+
+        Args:
+            config_file: a JSON file with a 'mysql' object that holds
+            the connection details.
+
+        Returns:
+            None
+
+        Raises:
+            BadConfigFileError: If the config_file fields are unexpected.
+        """
+        self.connection = None  # gets set according to config_file
+        self.database = None  # gets set according to config_file
+
+        with open(config_file) as json_data_file:
+            config = json.load(json_data_file)
+
+        if config.get('mysql', False):
+            mysql_config = config['mysql']
+            self.connection = mysql.connector.connect(
+                host=mysql_config['host'],
+                user=mysql_config['user'],
+                passwd=mysql_config['password']
+            )
+
+            self.database = mysql_config['database']
+
+            if self.connection is None or self.database is None:
+                raise BadConfigFileError('failed to connect to MySQL')
+        else:
+            msg = "config.json is missing {} field.".format('mysql')
+            raise BadConfigFileError(msg)
+
+    def yield_entities(self) -> str:
+        """Yields a list of all entities in the database."""
+        cursor = self.connection.cursor()
+        cursor.execute('use {}'.format(self.database))
+        cursor.execute('show tables')
+        # `fetchall` returns a list of single element tuples
+        tups = cursor.fetchall()
+        cursor.close()
+        for x in tups:
+            yield x[0]
+
+    def get_entities(self) -> str:
+        """
+        Returns a list of all entities in the database.
+
+        Example:
+        >>> from database_wrapper import NimbusMySQL
+        >>> db = NimbusMySQL()
+        >>> db.get_entities()
+        ['Clubs', 'Corequisites', 'Corrections', 'Courses', 'OfficeHours',
+        'PolyRatings', 'Prerequisites', 'Professors', 'ResearchInterests',
+        'ResponseFormats', 'ShortNames']
+        """
+        cursor = self.connection.cursor()
+        cursor.execute('use `{}`'.format(self.database))
+        cursor.execute('show tables')
+        # `fetchall` returns a list of single element tuples
+        tups = cursor.fetchall()
+        cursor.close()
+        return [x[0] for x in tups]
+
+    def get_relationships(self) -> str:
+        """Returns a list of all relationships between entities in database."""
+        pass
+
+    def get_unique(self, entity, prop) -> str:
+        """
+        """
+        cursor = self.connection.cursor()
+        cursor.execute('use `{}`'.format(self.database))
+        cursor.execute('select distinct({}) from {}'.format(prop, entity))
+        # `fetchall` returns a list of single element tuples
+        tups = cursor.fetchall()
+        cursor.close()
+        return [x[0] for x in tups]
+
+    def get_bitcount(self, entity, prop) -> str:
+        """
+        """
+        cursor = self.connection.cursor()
+        cursor.execute('use `{}`'.format(self.database))
+        cursor.execute('select bit_count(`{}`) from `{}`'.format(prop, entity))
+        # `fetchall` returns a list of single element tuples
+        tups = cursor.fetchall()
+        cursor.close()
+        return [x[0] for x in tups]
+
+    def close(self) -> None:
+        """Close the database connection"""
+        self.connection.close()
+        super().close()
+
+
+
+
+
+
+
+

Functions

+
+
+def get_current_time() +
+
+

Useful for answering questions like "Is prof availible now/tomorrow?"

+
+ +Expand source code + +
def get_current_time():
+    """
+    Useful for answering questions like "Is prof availible now/tomorrow?"
+    """
+    pass
+
+
+
+
+
+

Classes

+
+
+class BadConfigFileError +(message) +
+
+

Raised when the config.json file is badly formatter (e.g missing field).

+

Attributes

+
+
message
+
an explanation.
+
+
+ +Expand source code + +
class BadConfigFileError(Exception):
+    """Raised when the config.json file is badly formatter (e.g missing field).
+
+    Attributes:
+        message: an explanation.
+    """
+
+    def __init__(self, message: str):
+        self.message = message
+
+

Ancestors

+
    +
  • builtins.Exception
  • +
  • builtins.BaseException
  • +
+
+
+class NimbusDatabase +(config_file='config.json') +
+
+

An abstract class for interacting with the Nimbus database. +Concrete subclasses, such as NimbusMySQL, +should implement these operations such as connect

+

Inits Nimbus Database using the hostname, username, password +found inside the config_file.

+
+ +Expand source code + +
class NimbusDatabase(ABC):
+    """
+    An abstract class for interacting with the Nimbus database.
+    Concrete subclasses, such as NimbusMySQL,
+    should implement these operations such as `connect`
+    """
+
+    def __init__(self, config_file: str = 'config.json') -> None:
+        """
+        Inits Nimbus Database using the hostname, username, password
+        found inside the config_file.
+        """
+        pass
+
+    
+    @abstractmethod
+    def get_property_from_entity(self, 
+                                 prop: List[str],
+                                 entity: str, 
+                                 condition_field: Optional[str] = None,
+                                 condition_value: Optional[str] = None) -> List[str]:
+        """A higher-order function to get properties from entity in the database.
+
+        Example:
+        >>> db = NimbusDatabase("config.json")
+        >>> db.get_property_from_entity(["firstName", "lastName"], "Professors")
+        [("Foaad", "Khosmood"), ("John", "Clements"), ...]
+
+        >>> db.get_property_from_entity(["firstName", "lastName"], "Professors", "firstName", "Foaad")
+        [("Foaad", "Khosmood")]
+
+        Args:
+            entity: a string representing a table in the database.
+            prop: string(s) representing a field in the given table.
+            condition_field: (optional) string representing the column name.
+            condition_value: (optional) string representing the cell value.
+
+        Returns:
+            The list of prop of the entity (e.g. firstName of Professor)
+        """
+        pass
+
+    @abstractmethod
+    def get_property_from_related_entities(self,
+                                           prop: List[str],
+                                           entity1: str,
+                                           entity2: str,
+                                           key1: str, 
+                                           key2: Optional[str] = None,
+                                           condition_field: Optional[str] = None,
+                                           condition_value: Optional[str] = None) -> List[str]:
+        """A higher-order function to ????
+
+        Example:
+        >>> db = NimbusDatabase("config.json")
+        >>> db.get_property_from_related_entities(["firstName", "lastName", "ohRoom"], "Professors", "OfficeHours", "professorId")
+        [("Foaad", "Khosmood", "14-213"), ("John", "Clements", "14-210"), ...]
+
+        >>> db.get_property_from_related_entities(["firstName", "lastName"], "Professors", "OfficeHours", "professorId", "firstName", "Foaad")
+        [("Foaad", "Khosmood", "14-213")]
+
+        Args:
+            entity: TODO
+            prop: TODO
+
+        Returns:
+            TODO
+        """
+        pass
+        
+    
+    @abstractmethod
+    def get_entities(self) -> str:
+        pass
+
+
+    @abstractmethod
+    def get_fields_of_entity(self, entity1: str) -> str:
+        """
+        TODO: given an entity, return all the field names of that table in the database. 
+        """
+        pass
+
+    @abstractmethod
+    def get_unique(self, entity) -> str:
+        pass
+
+    @abstractmethod
+    def get_bitcount(self, entity) -> str:
+        pass
+
+    @abstractmethod
+    def close(self) -> None:
+        """
+        Simple Implementation Example:
+        ```
+        self.connection.close()
+        super().close()
+        ```
+        """
+        print("database connection was closed.")
+        pass
+
+    def __del__(self) -> None:
+        """
+        This method can make sure that the database connection is closed
+        before garbage references are collected.
+
+        There are reasons to not use `__del__`:
+        https://stackoverflow.com/q/1481488
+
+        Example:
+            >>> import database_wrapper
+            >>> db = database_wrapper.NimbusMySQL()
+            >>> del db
+            database object is being garbage collected...
+            database connection was closed.
+        """
+        print("database object is being garbage collected...")
+        self.close()
+        return
+
+

Ancestors

+
    +
  • abc.ABC
  • +
+

Subclasses

+ +

Methods

+
+
+def close(self) +
+
+

Simple Implementation Example:

+
self.connection.close()
+super().close()
+
+
+ +Expand source code + +
@abstractmethod
+def close(self) -> None:
+    """
+    Simple Implementation Example:
+    ```
+    self.connection.close()
+    super().close()
+    ```
+    """
+    print("database connection was closed.")
+    pass
+
+
+
+def get_bitcount(self, entity) +
+
+
+
+ +Expand source code + +
@abstractmethod
+def get_bitcount(self, entity) -> str:
+    pass
+
+
+
+def get_entities(self) +
+
+
+
+ +Expand source code + +
@abstractmethod
+def get_entities(self) -> str:
+    pass
+
+
+
+def get_fields_of_entity(self, entity1) +
+
+

TODO: given an entity, return all the field names of that table in the database.

+
+ +Expand source code + +
@abstractmethod
+def get_fields_of_entity(self, entity1: str) -> str:
+    """
+    TODO: given an entity, return all the field names of that table in the database. 
+    """
+    pass
+
+
+
+def get_property_from_entity(self, prop, entity, condition_field=None, condition_value=None) +
+
+

A higher-order function to get properties from entity in the database.

+

Example:

+
>>> db = NimbusDatabase("config.json")
+>>> db.get_property_from_entity(["firstName", "lastName"], "Professors")
+[("Foaad", "Khosmood"), ("John", "Clements"), ...]
+
+>>> db.get_property_from_entity(["firstName", "lastName"], "Professors", "firstName", "Foaad")
+[("Foaad", "Khosmood")]
+
+

Args

+
+
entity
+
a string representing a table in the database.
+
prop
+
string(s) representing a field in the given table.
+
condition_field
+
(optional) string representing the column name.
+
condition_value
+
(optional) string representing the cell value.
+
+

Returns

+
+
The list of prop of the entity (e.g. firstName of Professor)
+
 
+
+
+ +Expand source code + +
@abstractmethod
+def get_property_from_entity(self, 
+                             prop: List[str],
+                             entity: str, 
+                             condition_field: Optional[str] = None,
+                             condition_value: Optional[str] = None) -> List[str]:
+    """A higher-order function to get properties from entity in the database.
+
+    Example:
+    >>> db = NimbusDatabase("config.json")
+    >>> db.get_property_from_entity(["firstName", "lastName"], "Professors")
+    [("Foaad", "Khosmood"), ("John", "Clements"), ...]
+
+    >>> db.get_property_from_entity(["firstName", "lastName"], "Professors", "firstName", "Foaad")
+    [("Foaad", "Khosmood")]
+
+    Args:
+        entity: a string representing a table in the database.
+        prop: string(s) representing a field in the given table.
+        condition_field: (optional) string representing the column name.
+        condition_value: (optional) string representing the cell value.
+
+    Returns:
+        The list of prop of the entity (e.g. firstName of Professor)
+    """
+    pass
+
+
+ +
+

A higher-order function to ????

+

Example:

+
>>> db = NimbusDatabase("config.json")
+>>> db.get_property_from_related_entities(["firstName", "lastName", "ohRoom"], "Professors", "OfficeHours", "professorId")
+[("Foaad", "Khosmood", "14-213"), ("John", "Clements", "14-210"), ...]
+
+>>> db.get_property_from_related_entities(["firstName", "lastName"], "Professors", "OfficeHours", "professorId", "firstName", "Foaad")
+[("Foaad", "Khosmood", "14-213")]
+
+

Args

+
+
entity
+
TODO
+
prop
+
TODO
+
+

Returns

+
+
TODO
+
 
+
+
+ +Expand source code + +
@abstractmethod
+def get_property_from_related_entities(self,
+                                       prop: List[str],
+                                       entity1: str,
+                                       entity2: str,
+                                       key1: str, 
+                                       key2: Optional[str] = None,
+                                       condition_field: Optional[str] = None,
+                                       condition_value: Optional[str] = None) -> List[str]:
+    """A higher-order function to ????
+
+    Example:
+    >>> db = NimbusDatabase("config.json")
+    >>> db.get_property_from_related_entities(["firstName", "lastName", "ohRoom"], "Professors", "OfficeHours", "professorId")
+    [("Foaad", "Khosmood", "14-213"), ("John", "Clements", "14-210"), ...]
+
+    >>> db.get_property_from_related_entities(["firstName", "lastName"], "Professors", "OfficeHours", "professorId", "firstName", "Foaad")
+    [("Foaad", "Khosmood", "14-213")]
+
+    Args:
+        entity: TODO
+        prop: TODO
+
+    Returns:
+        TODO
+    """
+    pass
+
+
+
+def get_unique(self, entity) +
+
+
+
+ +Expand source code + +
@abstractmethod
+def get_unique(self, entity) -> str:
+    pass
+
+
+
+
+
+class NimbusMySQL +(config_file='config.json') +
+
+

An adapter for mysql-connector-python to fit our program.

+

The NimbusMySQL makes the mysql-connector-python interface +compatible with the our program's interface.

+

Attributes

+
+
config_file
+
a JSON file with the mysql details.
+
+

Inits Nimbus Database using the hostname, username, password +found inside the config_file.

+

Args

+
+
config_file
+
a JSON file with a 'mysql' object that holds
+
+

the connection details.

+

Returns

+
+
None
+
 
+
+

Raises

+
+
BadConfigFileError
+
If the config_file fields are unexpected.
+
+
+ +Expand source code + +
class NimbusMySQL(NimbusDatabase):
+    """An adapter for mysql-connector-python to fit our program.
+
+    The NimbusMySQL makes the mysql-connector-python interface
+    compatible with the our program's interface.
+
+    Attributes:
+        config_file: a JSON file with the mysql details.
+    """
+
+    def __init__(self, config_file: str = 'config.json') -> None:
+        """
+        Inits Nimbus Database using the hostname, username, password
+        found inside the config_file.
+
+        Args:
+            config_file: a JSON file with a 'mysql' object that holds
+            the connection details.
+
+        Returns:
+            None
+
+        Raises:
+            BadConfigFileError: If the config_file fields are unexpected.
+        """
+        self.connection = None  # gets set according to config_file
+        self.database = None  # gets set according to config_file
+
+        with open(config_file) as json_data_file:
+            config = json.load(json_data_file)
+
+        if config.get('mysql', False):
+            mysql_config = config['mysql']
+            self.connection = mysql.connector.connect(
+                host=mysql_config['host'],
+                user=mysql_config['user'],
+                passwd=mysql_config['password']
+            )
+
+            self.database = mysql_config['database']
+
+            if self.connection is None or self.database is None:
+                raise BadConfigFileError('failed to connect to MySQL')
+        else:
+            msg = "config.json is missing {} field.".format('mysql')
+            raise BadConfigFileError(msg)
+
+    def yield_entities(self) -> str:
+        """Yields a list of all entities in the database."""
+        cursor = self.connection.cursor()
+        cursor.execute('use {}'.format(self.database))
+        cursor.execute('show tables')
+        # `fetchall` returns a list of single element tuples
+        tups = cursor.fetchall()
+        cursor.close()
+        for x in tups:
+            yield x[0]
+
+    def get_entities(self) -> str:
+        """
+        Returns a list of all entities in the database.
+
+        Example:
+        >>> from database_wrapper import NimbusMySQL
+        >>> db = NimbusMySQL()
+        >>> db.get_entities()
+        ['Clubs', 'Corequisites', 'Corrections', 'Courses', 'OfficeHours',
+        'PolyRatings', 'Prerequisites', 'Professors', 'ResearchInterests',
+        'ResponseFormats', 'ShortNames']
+        """
+        cursor = self.connection.cursor()
+        cursor.execute('use `{}`'.format(self.database))
+        cursor.execute('show tables')
+        # `fetchall` returns a list of single element tuples
+        tups = cursor.fetchall()
+        cursor.close()
+        return [x[0] for x in tups]
+
+    def get_relationships(self) -> str:
+        """Returns a list of all relationships between entities in database."""
+        pass
+
+    def get_unique(self, entity, prop) -> str:
+        """
+        """
+        cursor = self.connection.cursor()
+        cursor.execute('use `{}`'.format(self.database))
+        cursor.execute('select distinct({}) from {}'.format(prop, entity))
+        # `fetchall` returns a list of single element tuples
+        tups = cursor.fetchall()
+        cursor.close()
+        return [x[0] for x in tups]
+
+    def get_bitcount(self, entity, prop) -> str:
+        """
+        """
+        cursor = self.connection.cursor()
+        cursor.execute('use `{}`'.format(self.database))
+        cursor.execute('select bit_count(`{}`) from `{}`'.format(prop, entity))
+        # `fetchall` returns a list of single element tuples
+        tups = cursor.fetchall()
+        cursor.close()
+        return [x[0] for x in tups]
+
+    def close(self) -> None:
+        """Close the database connection"""
+        self.connection.close()
+        super().close()
+
+

Ancestors

+ +

Methods

+
+
+def close(self) +
+
+

Close the database connection

+
+ +Expand source code + +
def close(self) -> None:
+    """Close the database connection"""
+    self.connection.close()
+    super().close()
+
+
+
+def get_bitcount(self, entity, prop) +
+
+
+
+ +Expand source code + +
def get_bitcount(self, entity, prop) -> str:
+    """
+    """
+    cursor = self.connection.cursor()
+    cursor.execute('use `{}`'.format(self.database))
+    cursor.execute('select bit_count(`{}`) from `{}`'.format(prop, entity))
+    # `fetchall` returns a list of single element tuples
+    tups = cursor.fetchall()
+    cursor.close()
+    return [x[0] for x in tups]
+
+
+
+def get_entities(self) +
+
+

Returns a list of all entities in the database.

+

Example:

+
>>> from database_wrapper import NimbusMySQL
+>>> db = NimbusMySQL()
+>>> db.get_entities()
+['Clubs', 'Corequisites', 'Corrections', 'Courses', 'OfficeHours',
+
+

'PolyRatings', 'Prerequisites', 'Professors', 'ResearchInterests', +'ResponseFormats', 'ShortNames']

+
+ +Expand source code + +
def get_entities(self) -> str:
+    """
+    Returns a list of all entities in the database.
+
+    Example:
+    >>> from database_wrapper import NimbusMySQL
+    >>> db = NimbusMySQL()
+    >>> db.get_entities()
+    ['Clubs', 'Corequisites', 'Corrections', 'Courses', 'OfficeHours',
+    'PolyRatings', 'Prerequisites', 'Professors', 'ResearchInterests',
+    'ResponseFormats', 'ShortNames']
+    """
+    cursor = self.connection.cursor()
+    cursor.execute('use `{}`'.format(self.database))
+    cursor.execute('show tables')
+    # `fetchall` returns a list of single element tuples
+    tups = cursor.fetchall()
+    cursor.close()
+    return [x[0] for x in tups]
+
+
+
+def get_relationships(self) +
+
+

Returns a list of all relationships between entities in database.

+
+ +Expand source code + +
def get_relationships(self) -> str:
+    """Returns a list of all relationships between entities in database."""
+    pass
+
+
+
+def get_unique(self, entity, prop) +
+
+
+
+ +Expand source code + +
def get_unique(self, entity, prop) -> str:
+    """
+    """
+    cursor = self.connection.cursor()
+    cursor.execute('use `{}`'.format(self.database))
+    cursor.execute('select distinct({}) from {}'.format(prop, entity))
+    # `fetchall` returns a list of single element tuples
+    tups = cursor.fetchall()
+    cursor.close()
+    return [x[0] for x in tups]
+
+
+
+def yield_entities(self) +
+
+

Yields a list of all entities in the database.

+
+ +Expand source code + +
def yield_entities(self) -> str:
+    """Yields a list of all entities in the database."""
+    cursor = self.connection.cursor()
+    cursor.execute('use {}'.format(self.database))
+    cursor.execute('show tables')
+    # `fetchall` returns a list of single element tuples
+    tups = cursor.fetchall()
+    cursor.close()
+    for x in tups:
+        yield x[0]
+
+
+
+

Inherited members

+ +
+
+class UnsupportedDatabaseError +(message) +
+
+

Raised when operation tries to connect to an unsupported database type.

+

Attributes

+
+
message
+
an explanation of why the expected database is unsupported.
+
+
+ +Expand source code + +
class UnsupportedDatabaseError(Exception):
+    """Raised when operation tries to connect to an unsupported database type.
+
+    Attributes:
+        message: an explanation of why the expected database is unsupported.
+    """
+
+    def __init__(self, message: str):
+        self.message = message
+
+

Ancestors

+
    +
  • builtins.Exception
  • +
  • builtins.BaseException
  • +
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/doc/NimbusDatabase/index.html b/doc/NimbusDatabase/index.html new file mode 100644 index 0000000..5a33360 --- /dev/null +++ b/doc/NimbusDatabase/index.html @@ -0,0 +1,60 @@ + + + + + + +NimbusDatabase API documentation + + + + + + + + + +
+
+
+

Module NimbusDatabase

+
+
+
+
+

Sub-modules

+
+
NimbusDatabase.database_wrapper
+
+

A wrapper module for the Nimbus data storage systems …

+
+
+
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file