Created
March 18, 2017 21:25
-
-
Save jeremylowery/5ba7fc3465c02255d4c7a8b71990cf45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_db = None | |
def set_db(db): | |
global _db | |
_db = db | |
def create_invoice(customer_id, line_items): | |
customer = customer_by_id(customer_id) | |
invoice_id = new_invoice_id() | |
insert_record('invoice', id=invoice_id, customer_id=customer_id) | |
for item in line_items: | |
insert_record('line_item', invoice_id=invoice_id, | |
amount=item.amount, product=item.product_id) | |
return invoice_id | |
# Example usage | |
def customer_by_id(customer_id) | |
cursor = _db.cursor() | |
cursor.execute("select * from customer where id=%s", (customer_id,)) | |
return next(cursor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment