segadb

# segadb/__init__.py

 
Package Contents
       
crypto
database
databasePartial
db_navigator
index
record
storage
table
transaction
users
views

 
Classes
       
builtins.object
segadb.crypto.CustomFernet
segadb.database.Database
segadb.databasePartial.PartialDatabase
segadb.index.Index
segadb.record.Record
segadb.record.EncryptedRecord
segadb.record.ImageRecord
segadb.record.TextRecord
segadb.record.TimeSeriesRecord
segadb.record.VectorRecord
segadb.storage.Storage
segadb.table.Table
segadb.transaction.Transaction
segadb.users.Authorization
segadb.users.User
segadb.users.UserManager
segadb.views.MaterializedView
segadb.views.View

 
class Authorization(builtins.object)
    Authorization(db)
 

 
  Methods defined here:
__init__(self, db)
Initializes a new instance of the class.
Attributes:
    permissions (dict): A dictionary to store user permissions.
add_permission(self, username, role)
Adds a permission to a specified role.
Args:
    role (str): The role to which the permission will be added.
    permission (str): The permission to be added to the role.
check_permission(self, username, permission)
Check if a user has a specific permission.
Args:
    username (str): The username of the user.
    role (str): The role to check for.
Returns:
    bool: True if the user has the permission, False otherwise.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class CustomFernet(builtins.object)
    CustomFernet(key)
 
A custom implementation of the Fernet symmetric encryption using AES in CBC mode.
 
  Methods defined here:
__init__(self, key)
Initializes the Crypto class with the given key.
Args:
    key (str): The base64 encoded key used for encryption and decryption.
Attributes:
    key (bytes): The decoded key used for encryption and decryption.
    backend (object): The backend used for cryptographic operations.
    block_size (int): The block size for the AES algorithm in bytes.
decrypt(self, token)
Decrypts the given token using AES encryption in CBC mode.
Args:
    token (str): The base64 encoded string to be decrypted.
Returns:
    str: The decrypted data as a string.
encrypt(self, data)
Encrypts the provided data using AES encryption with CBC mode and PKCS7 padding.
Args:
    data (str): The plaintext data to be encrypted.
Returns:
    str: The encrypted data encoded in URL-safe base64 format.

Static methods defined here:
generate_key()
Generates a secure random key.  
This function generates a 32-byte secure random key and encodes it using URL-safe Base64 encoding.
Returns:
    str: A URL-safe Base64 encoded string representing the secure random key.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Database(builtins.object)
    Database(name, db_logging=False, table_logging=False)
 

 
  Methods defined here:
__init__(self, name, db_logging=False, table_logging=False)
Initializes a new instance of the database with the given name.
Args:
    name (str): The name of the database.
    db_logging (bool, optional): If True, enables logging for the database. Defaults to False.
    table_logging (bool, optional): If True, enables logging for tables. Defaults to False.
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_table(self, table_name)
Retrieve a table from the database by its name.
Args:
    table_name (str): The name of the table to retrieve.
Returns:
    Table: The table object.
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.
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.
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 defined here:
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 defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class EncryptedRecord(Record)
    EncryptedRecord(record_id, data)
 

 
 
Method resolution order:
EncryptedRecord
Record
builtins.object

Methods defined here:
__init__(self, record_id, data)
Initializes a new instance of the EncryptedRecord class.
Args:
    record_id (int): The unique identifier for the record.
    data (str): The data associated with the record. Must contain a 'data' and 'key' field.
decrypt(self, key)
Decrypts the data using the encryption key.
Args:
    key (str): The key used for decryption
Returns:
    str: The decrypted data.

Methods inherited from Record:
add_to_index(self, key)
remove_from_index(self, key)

Readonly properties inherited from Record:
index
Returns the index of the record. 
@property decorator is used to make the method behave like an attribute. (Read-only)

Data descriptors inherited from Record:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class ImageRecord(Record)
    ImageRecord(record_id, image_path)
 

 
 
Method resolution order:
ImageRecord
Record
builtins.object

Methods defined here:
__init__(self, record_id, image_path)
Initializes a new instance of the ImageRecord class.
Args:
    record_id (int): The unique identifier for the record.
    image_path (str): The file path to the image.
get_image(self)
Converts the image data to a PIL Image object.
Returns:
    Image: The PIL Image object.
resize(self, percentage)
Resizes the image by a given percentage.
Args:
    percentage (float): The percentage to increase or decrease the size of the image.
Returns:
    Image: The resized PIL Image object.
to_dict(self)
Converts the ImageRecord to a dictionary, encoding image data to base64.
Returns:
    dict: The dictionary representation of the ImageRecord.

Readonly properties defined here:
image_data
image_path
image_size
Returns the size of the image in bytes.

Methods inherited from Record:
add_to_index(self, key)
remove_from_index(self, key)

Readonly properties inherited from Record:
index
Returns the index of the record. 
@property decorator is used to make the method behave like an attribute. (Read-only)

Data descriptors inherited from Record:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Index(builtins.object)
     Methods defined here:
__init__(self)
Initializes the index dictionary for the class instance.
__str__(self)
Returns a string representation of the index.
Returns:
    str: A string representation of the index.
add(self, key, record)
Adds a record to the index under the specified key.  
If the key does not exist in the index, it will be created.
Args:
    key (str): The key under which the record will be added.
    record (Any): The record to be added to the index.
find(self, key)
Find the value associated with the given key in the index.
Args:
    key: The key to search for in the index.
Returns:
    The value associated with the key if found, otherwise an empty list.
remove(self, key, record)
Remove a record from the index for a given key.
Args:
    key (str): The key from which the record should be removed.
    record (Any): The record to be removed from the index.
to_dict(self)
Returns a dictionary representation of the index.
Returns:
    dict: A dictionary representation of the index.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class MaterializedView(builtins.object)
    MaterializedView(name, query)
 

 
  Methods defined here:
__init__(self, name, query)
Initialize a new materialized view with a name and query.
Args:
    name (str): The name of the materialized view.
    query (function): A function that returns the data for the materialized view.
get_data(self)
Return the data for the materialized view.
Returns:
    list: The data for the materialized view.
refresh(self)
Refresh the data for the materialized view by re-executing the query.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
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

 
class Record(builtins.object)
    Record(record_id, data)
 

 
  Methods defined here:
__init__(self, record_id, data)
Initializes a new instance of the class.
Args:
    record_id (int): The unique identifier for the record.
    data (dict): The data associated with the record.
add_to_index(self, key)
remove_from_index(self, key)

Readonly properties defined here:
index
Returns the index of the record. 
@property decorator is used to make the method behave like an attribute. (Read-only)

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Storage(builtins.object)
    A utility class for saving, loading, and deleting database files.
 
  Static methods defined here:
backup(db, key=None, compress=False, dir=None, date=False)
Backup the database to a file. 
If none exists, a folder named 'backups_' + db.name will be created in the directory.
The database object is serialized into a JSON format and written to the specified file.
Each backup file is named 'db.name_backup_n.segadb', where n is the number of backups in the directory.
Args:
    db (Database): The database object to be saved.
    key (bytes, optional): The encryption key. If provided, the data will be encrypted before saving.
    compress (bool, optional): If True, the data will be compressed using zlib before saving.
    dir (str, optional): The directory where the backup will be saved. Default is None.       
    date (bool, optional): If True, the date will be appended to the filename. Default is False.
Returns:
    status (str): The status of the backup operation, as well as the path to the backup file.
db_to_dict(db)
Convert a database object to a dictionary.
Args:
    db (Database): The database object to be converted.
Returns:
    dict: A dictionary representation of the database object
decrypt(data, key)
Decrypt the data using the provided key.
delete(filename)
Delete the specified file from the filesystem.
Args:
    filename (str): The path to the file to be deleted.
encrypt(data, key)
Encrypt the data using the provided key.
generate_key()
Generate a key for encryption.
list_backups(dir=None, print_output=True)
List the backup files in the specified directory.
Args:
    dir (str, optional): The directory to search for backup files. Default is None.
Returns:
    list: A list of the backup files in the directory.
load(filename, key=None, user=None, password=None, compression=False, parrallel=False)
Load a database from a JSON file.
Args:
    filename (str): The path to the JSON file containing the database data.
    key (bytes, optional): The encryption key. If provided, the data will be decrypted after loading.
    compression (bool, optional): If True, the data will be decompressed using zlib after loading.
    parrallel (bool, optional): If True, the data will be loaded in parallel using multiprocessing.
Returns:
    Database: An instance of the Database class populated with the data from the JSON file.
restore(db, key=None, compress=False, user=None, password=None, dir=None, backup_name=None)
Restore a database from a backup file.
Args:
    db (Database): The database object to be restored.
    key (bytes, optional): The encryption key. If provided, the data will be decrypted after loading.
    compress (bool, optional): If True, the data will be decompressed using zlib after loading.
    user (str, optional): The username for authentication. Defaults to None.
    password (str, optional): The password for authentication. Defaults to None.
    dir (str, optional): The directory where the backup is saved. Default is None.
    backup_name (str, optional): The name of the backup file. Default is None. Will use the latest backup if None.
Returns:
    Database: An instance of the Database class populated with the data from the backup file.
save(db, filename, key=None, compress=False)
Save the database object to a JSON file.  
The database object is serialized into a JSON format and written to the specified file.  
The JSON structure includes the database name, tables, columns, records, next_id, and constraints.  
Args:
    db (Database): The database object to be saved.
    filename (str): The path to the file where the database will be saved.
    key (bytes, optional): The encryption key. If provided, the data will be encrypted before saving.
    compress (bool, optional): If True, the data will be compressed using zlib before saving.
save_table(table, filename, format='csv')
Save the table to a file in the specified format.
Args:
    table (Table): The table object to be saved.
    filename (str): The path to the file where the table will be saved.
    format (str): The format in which the table will be saved. Default is 'csv'.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Table(builtins.object)
    Table(name, columns, logger=None)
 

 
  Methods defined here:
__init__(self, name, columns, logger=None)
Initialize a new table with a name and columns.
Args:
    name (str): The name of the table.
    columns (list): A list of column names for the table.
    logger (Logger, optional): A logger object to use for logging. Defaults to None.
Attributes:
    name (str): The name of the table.
    columns (list): A list of column names for the table.
    records (list): A list to store the records of the table.
    next_id (int): The ID to be assigned to the next record.
    constraints (dict): A dictionary to store constraints for each column.
add_constraint = wrapper(self, *args, **kwargs) from segadb.table.log_method_call.
aggregate(self, group_column, agg_column, agg_func)
Perform an aggregation on a specified column using the provided aggregation function.
Args:
    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.
bulk_insert = wrapper(self, *args, **kwargs) from segadb.table.log_method_call.
delete = wrapper(self, *args, **kwargs) from segadb.table.log_method_call.
filter(self, condition)
Filter records based on a condition.
Args:
    condition (function): A function that takes a record as input and returns True if the record satisfies the condition, False otherwise.
Returns:
    Table: A new table containing the filtered records.
get_id_by_column = wrapper(self, *args, **kwargs) from segadb.table.log_method_call.
insert = wrapper(self, *args, **kwargs) from segadb.table.log_method_call.
join(self, other_table, on_column, other_column)
Perform an inner join with another table on specified columns.
Args:
    other_table (Table): The table to join with.
    on_column (str): The column in the current table to join on.
    other_column (str): The column in the other table to join on.
Returns:
    Table: A new table containing the joined records.
print_table(self, limit=None, pretty=False, index=False)
Prints the records in the table.
Args:
    limit (int, optional): The maximum number of records to print. If None, all records are printed. Defaults to None.
    pretty (bool, optional): If True, prints the table in a pretty format using the tabulate library. Defaults to False.
select = wrapper(self, *args, **kwargs) from segadb.table.log_method_call.
sort(self, column, ascending=True)
Sorts the records in the table based on the specified column.
Args:
    column (str): The column to sort by.
    ascending (bool, optional): If True, sorts in ascending order. Defaults to True.
Returns:
    Table: A new table containing the sorted records.
try_insert = wrapper(self, *args, **kwargs) from segadb.table.log_method_call.
update = wrapper(self, *args, **kwargs) from segadb.table.log_method_call.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class TextRecord(Record)
    TextRecord(record_id, text)
 

 
 
Method resolution order:
TextRecord
Record
builtins.object

Methods defined here:
__init__(self, record_id, text)
Initializes a new instance of the TextRecord class.
Args:
    record_id (int): The unique identifier for the record.
    text (str): The text data associated with the record.
to_lowercase(self)
Converts the text to lowercase.
Returns:
    str: The text in lowercase.
to_uppercase(self)
Converts the text to uppercase.
Returns:
    str: The text in uppercase.
word_count(self)
Counts the number of words in the text.
Returns:
    int: The number of words in the text.

Readonly properties defined here:
text

Methods inherited from Record:
add_to_index(self, key)
remove_from_index(self, key)

Readonly properties inherited from Record:
index
Returns the index of the record. 
@property decorator is used to make the method behave like an attribute. (Read-only)

Data descriptors inherited from Record:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class TimeSeriesRecord(Record)
    TimeSeriesRecord(record_id, time_series)
 

 
 
Method resolution order:
TimeSeriesRecord
Record
builtins.object

Methods defined here:
__init__(self, record_id, time_series)
Initializes a new instance of the class.
Args:
    record_id (int): The unique identifier for the record.
    data (dict): The data associated with the record.
moving_average(self, window_size)
Calculates the moving average of the time series.
Args:
    window_size (int): The window size for the moving average.
Returns:
    list: The moving average of the time series.

Readonly properties defined here:
time_series

Methods inherited from Record:
add_to_index(self, key)
remove_from_index(self, key)

Readonly properties inherited from Record:
index
Returns the index of the record. 
@property decorator is used to make the method behave like an attribute. (Read-only)

Data descriptors inherited from Record:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Transaction(builtins.object)
    Transaction(database)
 

 
  Methods defined here:
__init__(self, database)
Initializes a new transaction instance.
Args:
    database: The database object to associate with this transaction.
 
Attributes:
    database: The database object associated with this transaction.
    operations: A list to store the operations performed in this transaction.
add_operation(self, operation)
Adds an operation to the list of operations.
Args:
    operation: The operation to be added to the list.
begin(self)
Begins a new transaction.  
This method initializes the operations list and creates a shadow copy
of the current state of the database. The shadow copy is stored in the
database to allow for rollback if needed.
commit(self)
Commits the current transaction by executing all operations in the transaction.  
This method iterates over the list of operations and executes each one. After all operations
are executed, it clears the list of operations and discards the shadow copy of the database.
copy(self)
Copies a transaction object.
preview(self)
Previews the operations in the current transaction without committing or rolling back.
rollback(self)
Reverts the database to its previous state using a shadow copy if available.  
This method restores the database to the state saved in the shadow copy,
clears the list of operations, and removes the shadow copy reference.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class User(builtins.object)
    User(username, password, roles=None)
 

 
  Methods defined here:
__init__(self, username, password, roles=None)
Initialize a new User instance.
Args:
    username (str): The username of the user.
    password (str): The password of the user.
    roles (list, optional): A list of roles assigned to the user. Defaults to an empty list.
Attributes:
    username (str): The username of the user.
    password_hash (str): The hashed password of the user.
    roles (list): A list of roles assigned to the user.
check_password(self, password)
Check if the provided password matches the stored password hash.
Args:
    password (str): The plaintext password to check.
Returns:
    bool: True if the password matches the stored hash, False otherwise.

Static methods defined here:
hash_password(password)
Hashes a password using bcrypt.
Args:
    password (str): The password to be hashed.
Returns:
    bytes: The hashed password.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class UserManager(builtins.object)
    UserManager(db)
 

 
  Methods defined here:
__init__(self, db)
Initializes the Users class.
Args:
    db (Database): The database object to use for user management.
authenticate_user(self, username, password)
Authenticate a user by their username and password.
Args:
    username (str): The username of the user.
    password (str): The password of the user.
Returns:
    User: The authenticated user object if the username and password are correct.
    None: If the authentication fails.
get_user_permissions(self, username)
Get the permissions associated with a user.
Args:
    username (str): The username of the user.
Returns:
    list: A list of permissions associated with the user.
login_user(self, username, password)
Logs in a user by their username and password.
Args:
    username (str): The username of the user.
    password (str): The password of the user.
Returns:
    str: A session token if login is successful.
    None: If the login fails.
logout_user(self, session_token)
Logs out a user by their session token.
Args:
    session_token (str): The session token of the user.
register_user(self, username, password, roles=None)
Registers a new user with the given username, password, and optional roles.
Args:
    username (str): The username for the new user.
    password (str): The password for the new user.
    roles (list, optional): A list of roles assigned to the new user. Defaults to None.
Raises:
    ValueError: If the username already exists in the users dictionary.
remove_user(self, username)
Removes a user from the database.
Args:
    username (str): The username of the user to be removed.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class VectorRecord(Record)
    VectorRecord(record_id, vector)
 

 
 
Method resolution order:
VectorRecord
Record
builtins.object

Methods defined here:
__init__(self, record_id, vector)
Initializes a new instance of the VectorRecord class.
Args:
    record_id (int): The unique identifier for the record.
    vector (list): The vector data associated with the record.
dot_product(self, other_vector)
Calculates the dot product with another vector.
Args:
    other_vector (list): The other vector to calculate the dot product with.
Returns:
    float: The dot product of the two vectors.
magnitude(self)
Calculates the magnitude of the vector.
Returns:
    float: The magnitude of the vector.
normalize(self)
Normalizes the vector.
Returns:
    list: The normalized vector.

Readonly properties defined here:
vector

Methods inherited from Record:
add_to_index(self, key)
remove_from_index(self, key)

Readonly properties inherited from Record:
index
Returns the index of the record. 
@property decorator is used to make the method behave like an attribute. (Read-only)

Data descriptors inherited from Record:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class View(builtins.object)
    View(name, query)
 

 
  Methods defined here:
__init__(self, name, query)
Initialize a new view with a name and query.
Args:
    name (str): The name of the view.
    query (function): A function that returns the data for the view.
get_data(self)
Execute the query and return the data for the view.
Returns:
    list: The data for the view.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
Functions
       
db_navigator(stdscr, db)
Navigates through the database options using a curses-based interface.
The function initializes the curses environment, sets up color pairs, and defines a menu with various database options.
It then enters a main loop where it displays the main screen layout, handles user input to navigate through the menu,
and calls the corresponding display functions based on the selected menu option.
 
Args:
    stdscr: The curses window object.
    db: The database connection object.
 
Menu Options:
    - "DB Info": Displays database information.
    - "View Tables": Displays the list of tables.
    - "View Views": Displays the list of views.
    - "View Materialized Views": Displays the list of materialized views.
    - "View Stored Procedures": Displays the list of stored procedures.
    - "View Trigger Functions": Displays the list of trigger functions.
 
User Input:
    - 'q': Quit the navigator.
    - KEY_UP: Move the selection up.
    - KEY_DOWN: Move the selection down.
    - KEY_ENTER, 10, 13, KEY_RIGHT: Select the current menu option and display the corresponding information.

 
Data
        __all__ = ['Database', 'PartialDatabase', 'Index', 'Record', 'VectorRecord', 'TimeSeriesRecord', 'ImageRecord', 'TextRecord', 'EncryptedRecord', 'Storage', 'Table', 'Transaction', 'User', 'UserManager', 'Authorization', 'View', 'MaterializedView', 'CustomFernet', 'db_navigator']