Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the view table methods #4

Open
AkunoCode opened this issue Apr 8, 2023 · 0 comments
Open

Refactor the view table methods #4

AkunoCode opened this issue Apr 8, 2023 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@AkunoCode
Copy link
Owner

The view_products(), view_sales(), view_customers(), view_admins() methods could be refactored by creating a new display_table() method which takes a table name and a list of column names as arguments

Sample code from chatGPT:

def display_table(self, table_name, columns):
    """Display data from the specified table"""

    # Query the table and fetch the data
    self.cursor.execute(f"SELECT * FROM {table_name}")
    data = self.cursor.fetchall()

    # Display the data in a tabular format
    labels = "\t".join(columns)
    print(labels)

    for row in data:
        values = "\t".join(str(x) for x in row)
        print(values)

    input("Press Enter to continue...\n")

def view_products(self):
    """Display all products in the database"""

    # Define the columns to display
    columns = ["Product ID", "Name", "Price", "Quantity in Stock"]

    # Call the display_table function with the appropriate arguments
    self.display_table("products", columns)
@AkunoCode AkunoCode added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 8, 2023
@AkunoCode AkunoCode self-assigned this Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant