db.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. #########################################################################
  3. ## This scaffolding model makes your app work on Google App Engine too
  4. ## File is released under public domain and you can use without limitations
  5. #########################################################################
  6. ## if SSL/HTTPS is properly configured and you want all HTTP requests to
  7. ## be redirected to HTTPS, uncomment the line below:
  8. # request.requires_https()
  9. ## app configuration made easy. Look inside private/appconfig.ini
  10. from gluon.contrib.appconfig import AppConfig
  11. ## once in production, remove reload=True to gain full speed
  12. myconf = AppConfig(reload=True)
  13. DATABASE = None
  14. DATABASE_URI = "mysql://benchmarkdbuser:benchmarkdbpass@localhost:3306/hello_world"
  15. if not request.env.web2py_runtime_gae:
  16. ## if NOT running on Google App Engine use SQLite or other DB
  17. db = DAL(DATABASE_URI, fake_migrate_all=True)
  18. DATABASE = db
  19. else:
  20. ## connect to Google BigTable (optional 'google:datastore://namespace')
  21. db = DAL(DATABASE_URI, fake_migrate_all=True)
  22. DATABASE = db
  23. ## store sessions and tickets there
  24. session.connect(request, response, db=db)
  25. ## or store session in Memcache, Redis, etc.
  26. ## from gluon.contrib.memdb import MEMDB
  27. ## from google.appengine.api.memcache import Client
  28. ## session.connect(request, response, db = MEMDB(Client()))
  29. ## by default give a view/generic.extension to all actions from localhost
  30. ## none otherwise. a pattern can be 'controller/function.extension'
  31. response.generic_patterns = ['*'] if request.is_local else []
  32. db.define_table("world",
  33. Field("id"),
  34. Field("randomNumber")
  35. )
  36. db.define_table("fortune",
  37. Field("id"),
  38. Field("message")
  39. )