| | |
- builtins.object
-
- Table
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 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 log_method_call.
- delete = wrapper(self, *args, **kwargs) from 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 log_method_call.
- insert = wrapper(self, *args, **kwargs) from 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 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 log_method_call.
- update = wrapper(self, *args, **kwargs) from log_method_call.
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |