Beispiel #1
0
def update(name, col_search=None, val_search=None):
    try:
        cols = []
        vals = []
        val = 0
        if col_search == None:
            col_search = columns[name][SelectionMenu.get_selection(
                [i for i in columns[name]],
                show_exit_option=False,
                title="Choose column to search",
            )]
        if val_search == None:
            val_search = Screen().input("Enter value to update: ")
        Screen().println(
            'Enter columns, text values must be surrounded by "\'"')
        Screen().println("Empty lines will be ignored")
        for i in range(1, len(columns[name])):
            col = columns[name][i]
            val = Screen().input(f"{(col)}: ")
            if bool(val and not val.isspace()):
                cols.append(col)
                vals.append(val)
        ens = db.update(name, cols, vals, col_search, val_search)
        if isinstance(ens, Exception):
            Screen().input(f"Derror: {ens}")
            return
        else:
            Screen().input(f"Updated { ens } items")
    except Exception as e:
        Screen().input("\n".join(
            [f"CError: {e}", "Press any key to continue..."]))
Beispiel #2
0
def insert(name):
    try:
        cols = []
        vals = []
        val = 0
        Screen().println(
            'Enter columns, text values must be surrounded by "\'"')
        Screen().println("Empty lines will be ignored")
        for i in range(1, len(columns[name])):
            col = columns[name][i]
            val = Screen().input(f"{(col)}: ")
            if bool(val and not val.isspace()):
                cols.append(col)
                vals.append(val)
        en = db.insert(name, cols, vals)
        if isinstance(en, Exception):
            Screen().input(f"Derror: {en}")
            return
        if name == "Seller":
            prod_ids = Screen().input(
                "Enter products id's, separated by commas: ")
            ens_arr = []
            for prod_id in prod_ids.split(","):
                ens_arr.append(f"""(
                    { prod_id },
                    { str(en[0][0]) }
                )""")
            ens = db.insert("SellerProduct", ["product_id", "seller_id"],
                            [ens_arr])
            if isinstance(ens, Exception):
                Screen().input(f"Derror: {ens}")
                return
            else:
                Screen().println(f"Inserted { len(ens) } items")
        elif name == "Product":
            sell_ids = Screen().input(
                "Enter sellers id's, separated by commas: ")
            ens_arr = []
            for sell_id in sell_ids.split(","):
                ens_arr.append(f"""(
                    { sell_id },
                    { str(en[0][0]) }
                )""")
            ens = db.insert(
                "SellerProduct",
                ["seller_id", "product_id"],
                [ens_arr],
            )
            if isinstance(ens, Exception):
                Screen().input(f"Derror: {ens}")
                return
            else:
                Screen().println(f"Inserted { ens } items")
    except Exception as e:
        Screen().input("\n".join(
            [f"CError: {e}", "Press any key to continue..."]))