pyprediktorutilities.dwh package
Submodules
pyprediktorutilities.dwh.dwh module
- class pyprediktorutilities.dwh.dwh.Dwh(url: str, database: str, username: str, password: str, driver_index: int = -1)[source]
Bases:
object
Access a PowerView Data Warehouse or other SQL databases.
- Parameters:
- connection
The connection object
- Type:
pyodbc.Connection
- cursor
The cursor object
- Type:
pyodbc.Cursor
- execute(query: str, *args, **kwargs) List[Any] [source]
Execute the SQL query and return the results.
For instance, if we create a new record in DWH by calling a stored procedure returning the id of the inserted element or in our query we use SELECT SCOPE_IDENTITY() AS LastInsertedId;, the DWH is going to return data after executing our write request.
Please note that here we expect a single result set. Therefore DWH is obligated to return only one data set and also we’re obligated to construct our query according to this requirement.
Use that method to CREATE, UPDATE, DELETE or execute business logic. To NOT use for GET.
- Parameters:
query (str) – The SQL query to execute.
*args – Variable length argument list to pass to cursor.execute().
**kwargs – Arbitrary keyword arguments to pass to cursor.execute().
- Returns:
The results of the query.
- Return type:
List[Any]
- fetch(query: str, to_dataframe: bool = False) List[Any] [source]
Execute the SQL query to get results from DWH and return the data.
Use that method for getting data. That means that if you use SELECT or you’d like to call a stored procedure that returns one or more sets of data, that is the correct method to use.
Use that method to GET.
- Parameters:
- Returns:
- The results of the query. If DWH returns multiple
data sets, this method is going to return a list of result sets (lists). If DWH returns a single data set, the method is going to return a list representing the single result set.
If to_dataframe is True, the data inside each data set is going to be in DataFrame format.
- Return type:
List[Any]