Skip to content

Instantly share code, notes, and snippets.

@jeremylowery
Created March 18, 2017 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremylowery/5ba7fc3465c02255d4c7a8b71990cf45 to your computer and use it in GitHub Desktop.
Save jeremylowery/5ba7fc3465c02255d4c7a8b71990cf45 to your computer and use it in GitHub Desktop.
_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