コード例 #1
0
def show_product(name_product: str):
    """Starts session to show a product and automatically ends it"""
    with Session.begin() as session:
        statement = select(
            Product.description).filter_by(description=name_product)
        result = session.execute(statement).all()
        print(result)
コード例 #2
0
def all_products():
    """Starts session to show all products and automatically ends it"""
    with Session.begin() as session:
        statement = select(Product.serial, Product.description, Product.price)
        result = session.execute(statement).all()
        for row in result:
            print(row)
コード例 #3
0
def show_customer(name_customer: str):
    """Starts session to show a customer and automatically ends it"""
    with Session.begin() as session:
        statement = select(Customer.name, Customer.address,
                           Customer.phone).filter_by(name=name_customer)
        result = session.execute(statement).all()
        print(result)
コード例 #4
0
def get_product(name_product: str) -> List[str]:
    """Starts session to show a product and automatically ends it"""
    with Session.begin() as session:
        statement = select(Product.serial, Product.description,
                           Product.price).filter_by(description=name_product)
        result = session.execute(statement).all()
        product_list = list(flatten(result))
    return product_list
コード例 #5
0
def all_customers():
    """Starts session to show all customers and automatically ends it"""
    with Session.begin() as session:
        statement = select(Customer.name,\
                Customer.address, Customer.phone)
        result = session.execute(statement).all()
        for row in result:
            print(row)
コード例 #6
0
def all_invoices():
    """Starts session to show all invoices and automatically ends it"""
    with Session.begin() as session:
        stmt = select(Invoice.id, Invoice.serial, Invoice.customer_id)
        result = session.execute(stmt).all()
        products_invoices_list = all_products_invoices()
        for row in zip(result, products_invoices_list):
            print(row)
コード例 #7
0
def get_customer(name_customer: str) -> List[str]:
    """Starts session to show a customer and automatically ends it"""
    with Session.begin() as session:
        statement = select(Customer.name, Customer.address,
                           Customer.phone).filter_by(name=name_customer)
        result = session.execute(statement).all()
        customer_iterable = flatten(result)
        customer_list = list(customer_iterable)
        return customer_list
コード例 #8
0
def show_invoice(serial_for_invoice: str):
    """Starts session to show an invoice and automatically ends it"""
    with Session.begin() as session:
        statement = select(Invoice.id, Invoice.serial,
                           Invoice.customer_relationship).where(
                               Invoice.serial == serial_for_invoice)
        result = session.execute(statement).all()
        products_invoice_object = show_products_invoice(result[0][0])
        result.append(products_invoice_object)
        print(result)
コード例 #9
0
def get_invoice_serial() -> int:
    """Starts session to show a invoice and automatically ends it"""
    with Session.begin() as session:
        statement = select(Invoice.serial)
        result = session.execute(statement).all()
        print(result)
        if not result:
            return 1000
        result = flatten(result)
        result = list(result)
        result = int(result[-1])
        return result
コード例 #10
0
def all_products_invoices():
    with Session.begin() as session:
        statement = select(ProductsInvoice.id,
                            ProductsInvoice.product_id,
                            ProductsInvoice.invoice_id,
                            ProductsInvoice.product_serial,
                            ProductsInvoice.product_description,
                            ProductsInvoice.product_rate,
                            ProductsInvoice.product_quantity,
                            ProductsInvoice.product_total)
        result = session.execute(statement).all()
        print(result)
        return result
コード例 #11
0
def show_products_invoice(products_invoice_id: str):
    with Session.begin() as session:
        statement = select(ProductsInvoice.id,
                            ProductsInvoice.product_id,
                            ProductsInvoice.invoice_id,
                            ProductsInvoice.product_serial,
                            ProductsInvoice.product_description,
                            ProductsInvoice.product_rate,
                            ProductsInvoice.product_quantity,
                            ProductsInvoice.product_total).\
                                            filter_by(id=products_invoice_id)
        result = session.execute(statement).all()
        return result


                                                                     
コード例 #12
0
def remove_products_invoice(products_invoice_id: str):
    with Session.begin() as session:
        statement = delete(ProductsInvoice.id == products_invoice_id).\
                           execution_options(synchronize_session="fetch")
        session.execute(statement)
コード例 #13
0
def add_invoice(filled_invoice: Invoice):
    """Starts session to add invoice and automatically ends it"""
    with Session.begin() as session:
        session.add(filled_invoice)
        session.commit()
コード例 #14
0
def remove_invoice(serial_for_invoice: str):
    """Starts session to remove invoice and automatically ends it"""
    with Session.begin() as session:
        statement = delete(Invoice).where(Invoice.serial == serial_for_invoice).\
                execution_options(synchronize_session='fetch')
        session.execute(statement)
コード例 #15
0
def remove_customer(name_customer: str):
    """Starts session to remove customer and automatically ends it"""
    with Session.begin() as session:
        statement = delete(Customer).where(Customer.name == name_customer).\
                execution_options(synchronize_session='fetch')
        session.execute(statement)
コード例 #16
0
def remove_product(name_product: str):
    """Starts session to remove product and automatically ends it"""
    with Session.begin() as session:
        statement = delete(Product).where(Product.description == name_product).\
                execution_options(synchronize_session='fetch')
        session.execute(statement)
コード例 #17
0
def add_customer(customer_object: Customer):
    """Starts session to add customer and automatically ends it"""
    with Session.begin() as session:
        session.add(customer_object)
        session.commit()
コード例 #18
0
def add_products_invoice(products_invoice_object: ProductsInvoice):
    with Session.begin() as session:
        session.add(products_invoice_object)
        session.commit()
コード例 #19
0
def add_product(name_product: Product):
    """Starts session to add product and automatically ends it"""
    with Session.begin() as session:
        session.add(name_product)
        session.commit()