summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql/gaerdbms.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-02-02 18:40:56 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-02-02 18:40:56 -0500
commita6697a83e57ef58780e3d6da43f907f88a60e3a8 (patch)
tree74545ebf8a058cd0a249656269e4de5500f33315 /lib/sqlalchemy/dialects/mysql/gaerdbms.py
parent681a0b1d674135b498e98e82fa8527b505fb404a (diff)
downloadsqlalchemy-a6697a83e57ef58780e3d6da43f907f88a60e3a8.tar.gz
Added a conditional import to the ``gaerdbms`` dialect which attempts
to import rdbms_apiproxy vs. rdbms_googleapi to work on both dev and production platforms. Also now honors the ``instance`` attribute. Courtesy Sean Lynch. [ticket:2649]
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/gaerdbms.py')
-rw-r--r--lib/sqlalchemy/dialects/mysql/gaerdbms.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/gaerdbms.py b/lib/sqlalchemy/dialects/mysql/gaerdbms.py
index d84a1e896..a93a78b73 100644
--- a/lib/sqlalchemy/dialects/mysql/gaerdbms.py
+++ b/lib/sqlalchemy/dialects/mysql/gaerdbms.py
@@ -7,7 +7,7 @@
.. dialect:: mysql+gaerdbms
:name: Google Cloud SQL
:dbapi: rdbms
- :connectstring: mysql+gaerdbms:///<dbname>?instance=instancename
+ :connectstring: mysql+gaerdbms:///<dbname>?instance=<instancename>
:url: https://developers.google.com/appengine/docs/python/cloud-sql/developers-guide
This dialect is based primarily on the :mod:`.mysql.mysqldb` dialect with minimal
@@ -35,8 +35,20 @@ class MySQLDialect_gaerdbms(MySQLDialect_mysqldb):
@classmethod
def dbapi(cls):
- from google.appengine.api import rdbms
- return rdbms
+ # from django:
+ # http://code.google.com/p/googleappengine/source/
+ # browse/trunk/python/google/storage/speckle/
+ # python/django/backend/base.py#118
+ # see also [ticket:2649]
+ # see also http://stackoverflow.com/q/14224679/34549
+ from google.appengine.api import apiproxy_stub_map
+
+ if apiproxy_stub_map.apiproxy.GetStub('rdbms'):
+ from google.storage.speckle.python.api import rdbms_apiproxy
+ return rdbms_apiproxy
+ else:
+ from google.storage.speckle.python.api import rdbms_googleapi
+ return rdbms_googleapi
@classmethod
def get_pool_class(cls, url):
@@ -44,9 +56,13 @@ class MySQLDialect_gaerdbms(MySQLDialect_mysqldb):
return NullPool
def create_connect_args(self, url):
- return [[], {'database': url.database,
- 'user': url.username,
- 'password': url.password}]
+ opts = url.translate_connect_args()
+ # 'dsn' and 'instance' are because we are skipping
+ # the traditional google.api.rdbms wrapper
+
+ opts['dsn'] = ''
+ opts['instance'] = url.query['instance']
+ return [], opts
def _extract_error_code(self, exception):
match = re.compile(r"^(\d+):").match(str(exception))