summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql/gaerdbms.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-05-26 13:10:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-05-26 13:10:40 -0400
commit6b810a9141dcc65cd462066e741937f32fbc745a (patch)
tree84e4c8adcb39b6c88a36d1c974d4fefab5f74e0d /lib/sqlalchemy/dialects/mysql/gaerdbms.py
parent8c3d847db027c64f67a694975de9d36f6c2e50ce (diff)
downloadsqlalchemy-6b810a9141dcc65cd462066e741937f32fbc745a.tar.gz
- add new google app engine DBAPI, [ticket:2484]
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/gaerdbms.py')
-rw-r--r--lib/sqlalchemy/dialects/mysql/gaerdbms.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/gaerdbms.py b/lib/sqlalchemy/dialects/mysql/gaerdbms.py
new file mode 100644
index 000000000..f84a5d2dd
--- /dev/null
+++ b/lib/sqlalchemy/dialects/mysql/gaerdbms.py
@@ -0,0 +1,61 @@
+# mysql/gaerdbms.py
+# Copyright (C) 2005-2012 the SQLAlchemy authors and contributors <see AUTHORS file>
+#
+# This module is part of SQLAlchemy and is released under
+# the MIT License: http://www.opensource.org/licenses/mit-license.php
+"""Support for Google Cloud SQL on Google App Engine.
+
+This dialect is based primarily on the :mod:`.mysql.mysqldb` dialect with minimal
+changes.
+
+.. versionadded:: 0.7.8
+
+Connecting
+----------
+
+Connect string format::
+
+ mysql+gaerdbms:///<dbname>
+
+E.g.::
+
+ create_engine('mysql+gaerdbms:///mydb',
+ connect_args={"instance":"instancename"})
+
+Pooling
+-------
+
+Google App Engine connections appear to be randomly recycled,
+so the dialect does not pool connections. The :class:`.NullPool`
+implementation is installed within the :class:`.Engine` by
+default.
+
+"""
+
+from sqlalchemy.dialects.mysql.mysqldb import MySQLDialect_mysqldb
+from sqlalchemy.pool import NullPool
+import re
+
+
+class MySQLDialect_gaerdbms(MySQLDialect_mysqldb):
+
+ @classmethod
+ def dbapi(cls):
+ from google.appengine.api import rdbms
+ return rdbms
+
+ @classmethod
+ def get_pool_class(cls, url):
+ # Cloud SQL connections die at any moment
+ return NullPool
+
+ def create_connect_args(self, url):
+ return [[],{'database':url.database}]
+
+ def _extract_error_code(self, exception):
+ match = re.compile(r"^(\d+):").match(str(exception))
+ code = match.group(1)
+ if code:
+ return int(code)
+
+dialect = MySQLDialect_gaerdbms \ No newline at end of file