PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/SQLAlchemy-0.7.8/lib/sqlalchemy/dialects/mysql/gaerdbms.py

#
Python | 61 lines | 40 code | 0 blank | 21 comment | 0 complexity | bd1e5b30e83372df0344673357c5b41f MD5 | raw file
  1. # mysql/gaerdbms.py
  2. # Copyright (C) 2005-2012 the SQLAlchemy authors and contributors <see AUTHORS file>
  3. #
  4. # This module is part of SQLAlchemy and is released under
  5. # the MIT License: http://www.opensource.org/licenses/mit-license.php
  6. """Support for Google Cloud SQL on Google App Engine.
  7. This dialect is based primarily on the :mod:`.mysql.mysqldb` dialect with minimal
  8. changes.
  9. .. versionadded:: 0.7.8
  10. Connecting
  11. ----------
  12. Connect string format::
  13. mysql+gaerdbms:///<dbname>
  14. E.g.::
  15. create_engine('mysql+gaerdbms:///mydb',
  16. connect_args={"instance":"instancename"})
  17. Pooling
  18. -------
  19. Google App Engine connections appear to be randomly recycled,
  20. so the dialect does not pool connections. The :class:`.NullPool`
  21. implementation is installed within the :class:`.Engine` by
  22. default.
  23. """
  24. from sqlalchemy.dialects.mysql.mysqldb import MySQLDialect_mysqldb
  25. from sqlalchemy.pool import NullPool
  26. import re
  27. class MySQLDialect_gaerdbms(MySQLDialect_mysqldb):
  28. @classmethod
  29. def dbapi(cls):
  30. from google.appengine.api import rdbms
  31. return rdbms
  32. @classmethod
  33. def get_pool_class(cls, url):
  34. # Cloud SQL connections die at any moment
  35. return NullPool
  36. def create_connect_args(self, url):
  37. return [[],{'database':url.database}]
  38. def _extract_error_code(self, exception):
  39. match = re.compile(r"^(\d+):").match(str(exception))
  40. code = match.group(1)
  41. if code:
  42. return int(code)
  43. dialect = MySQLDialect_gaerdbms