| | |
- segadb.database.Database(builtins.object)
-
- PartialDatabase
class PartialDatabase(segadb.database.Database) |
| |
PartialDatabase(name, file_path, views=True, materialized_views=True, stored_procedures=True, triggers=True)
|
| |
- Method resolution order:
- PartialDatabase
- segadb.database.Database
- builtins.object
Methods defined here:
- __init__(self, name, file_path, views=True, materialized_views=True, stored_procedures=True, triggers=True)
- Initialize a new partial database object.
Args:
name (str): The name of the database.
file_path (str): The path to the database file.
views (bool, optional): Whether to load views. Defaults to None.
materialized_views (bool, optional): Whether to load materialized views. Defaults to None.
stored_procedures (bool, optional): Whether to load stored procedures. Defaults to None.
triggers (bool, optional): Whether to load triggers. Defaults to None.
- active_tables(self)
- Get a list of active tables in the database.
Returns:
list: A list of table names.
- deactivate_table(self, table_name)
- Move a table from active memory to dormant storage.
Args:
table_name (str): The name of the table to move.
- dormant_tables(self)
- Get a list of tables that are not currently loaded into memory.
Returns:
list: A list of table names.
- get_table(self, table_name, session_token=None)
- Retrieve a table from the database by its name. Load the table into memory if it is not already loaded.
Args:
table_name (str): The name of the table to retrieve.
session_token (str, optional): The session token of the user performing the action.
Returns:
Table: The table object.
- print_db(self, index=False, limit=None, tables=True, views=False, materialized_views=False, stored_procedures=False, triggers=False)
- Print the database tables, including their names, columns, constraints, and records.
Args:
index (bool, optional): Whether to print the index of each record. Defaults to False.
limit (int, optional): The maximum number of records to print for each table. Defaults to None.
tables (bool, optional): Whether to print the tables. Defaults to True.
views (bool, optional): Whether to print the views. Defaults to False.
materialized_views (bool, optional): Whether to print the materialized views. Defaults to False.
Methods inherited from segadb.database.Database:
- add_constraint = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- add_role = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- add_stored_procedure = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- add_trigger = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- aggregate_table(self, table_name, group_column, agg_column, agg_func)
- Perform an aggregation on a specified column in a table using the provided aggregation function.
Args:
table_name (str): The name of the table.
group_column (str): The column to group by.
agg_column (str): The column to aggregate.
agg_func (str): The aggregation function to apply. Supported values are 'MIN', 'MAX', 'COUNT', 'SUM', 'AVG', 'COUNT_DISTINCT'.
Returns:
Table: A new table containing the result of the aggregation.
- authenticate_user(self, username, password)
- Authenticates a user by their username and password.
Args:
username (str): The username of the user.
password (str): The password of the user.
Returns:
dict or None: The user dictionary if authentication is successful, None otherwise.
- check_permission(self, username, permission)
- Check if a user has a specific permission.
Args:
username (str): The username of the user.
permission (str): The permission to check for.
Returns:
bool: True if the user has the permission, False otherwise.
- check_role(self, username, role)
- Check if a user has a specific role.
Args:
username (str): The username of the user to check.
role (str): The role to check for.
Returns:
bool: True if the user has the specified role, False otherwise.
- copy(self)
- Create a deep copy of the database state.
This method uses the `copy` module to create a deep copy of the current
database instance, ensuring that all nested objects are also copied.
Returns:
A new instance of the database with the same state as the original.
- create_authorization(self)
- Create a new instance of the Authorization class.
Returns:
Authorization: A new instance of the Authorization class.
- create_materialized_view = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- create_session = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- create_table = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- create_table_from_csv = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- create_user_manager(self)
- Create a new instance of the UserManager class.
Returns:
UserManager: A new instance of the UserManager class.
- create_view = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- delete_materialized_view = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- delete_session = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- delete_stored_procedure = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- delete_trigger = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- delete_view = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- drop_table = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- execute_stored_procedure = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- execute_triggers = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- filter_table(self, table_name, condition)
- Filter records in a table based on a condition.
Args:
table_name (str): The name of the table.
condition (function): A function that takes a record as input and returns True if the record satisfies the condition, False otherwise.
Example: lambda record: record.data["product"] == "Laptop"
Returns:
Table: A new table containing the filtered records.
- get_db_size(self)
- Calculate the size of the database in bytes.
Returns:
int: The size of the database in bytes.
- get_materialized_view(self, view_name)
- Retrieve a materialized view by name.
Args:
view_name (str): The name of the materialized view.
Returns:
MaterializedView: The materialized view object.
- get_stored_procedure(self, name)
- Retrieve a stored procedure by name.
Args:
name (str): The name of the stored procedure.
Returns:
function: The stored procedure function.
- get_user(self, username)
- Retrieve user data from the Users table based on the provided username.
Args:
username (str): The username of the user to retrieve.
Returns:
dict: A dictionary containing the user's data if found, otherwise None.
- get_username_by_session = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- get_view(self, view_name)
- Retrieve a view by name.
Args:
view_name (str): The name of the view.
Returns:
View: The view object.
- join_tables(self, table_name1, table_name2, on_column, other_column)
- Perform an inner join between two tables on specified columns.
Args:
table_name1 (str): The name of the first table.
table_name2 (str): The name of the second table.
on_column (str): The column in the first table to join on.
other_column (str): The column in the second table to join on.
Returns:
Table: A new table containing the joined records.
- refresh_materialized_view = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- register_user = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- remove_user = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
- restore(self, state)
- Restore the database state from a shadow copy.
Args:
state (object): An object containing the state to restore, including tables and name attributes.
Returns:
self: The instance of the database with the restored state.
- show_db_with_curses(self)
- # Utility Methods
# ---------------------------------------------------------------------------------------------
- update_table = wrapper(self, *args, **kwargs) from segadb.database.log_method_call.
Static methods inherited from segadb.database.Database:
- load_sample_database(name='SampleDB', n_users=10, n_orders=100, n_products=50, n_reviews=200, n_categories=10, n_suppliers=20, db_logging=False, table_logging=False)
- Create a sample database with predefined tables and data for testing and demonstration purposes.
Args:
name (str): The name of the sample database.
Returns:
Database: An instance of the Database class populated with sample data.
Data descriptors inherited from segadb.database.Database:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |