From anonymous, 6 Years ago, written in Python.
Embed
  1. import sqlalchemy.ext.declarative
  2. from bottle import route, post
  3. from sqlalchemy import (Integer, Column, String)
  4.  
  5. DBBase = sqlalchemy.ext.declarative.declarative_base()
  6. engine = sqlalchemy.create_engine('mysql://foo:bar@localhost/dbname')
  7.  
  8. class Foo(Base):
  9.     __tablename__ = 'foo'
  10.     blah = Column(Integer, primary_key=True)
  11.     blub = Column(String(45))
  12.  
  13. prices = { 'foo': 10, 'bar': 20 }
  14.  
  15. @route('/pricelist')
  16. def get_list():
  17.     h = "<html><head><title>foo</title><body><ul>"
  18.     for elem in prices:
  19.         h += "<li>{}: {}</li>".format(elem, prices[elem])
  20.     h += "</ul></body></html>"
  21.     return h
  22.  
  23. @post('/pricelist')
  24. def post_list(db):
  25.     # query example: db.Query(Foo).filter_by(blub="blah").all()
  26.     row = Foo(blah=request.forms.blah)
  27.     db.add(row)