Skip to content

Commit

Permalink
support for gcloud sql v2. thanks Karoly Kantor
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Jul 3, 2017
1 parent 6fd68e4 commit 466a39f
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 146 deletions.
9 changes: 4 additions & 5 deletions pydal/adapters/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ def ignore_cache_for(self, entities=None):


# based on this: https://cloud.google.com/appengine/docs/standard/python/cloud-sql/
@adapters.register_for('google:mysql')
@adapters.register_for('google:MySQLdb')
class GoogleMySQL(MySQL):
uploads_in_blob = True
drivers = ('MySQLdb',)

def __init__(self, *args, **kwargs):
super(GoogleMySQL, self).__init__(*args, **kwargs)
Expand All @@ -109,9 +110,6 @@ def _find_work_folder(self):
if os.path.isabs(self.folder) and self.folder.startswith(os.getcwd()):
self.folder = os.path.relpath(self.folder, os.getcwd())

def find_driver(self):
self.driver = "pymysql"

def clear_cache(self):
ndb.get_context().clear_cache()

Expand All @@ -120,9 +118,10 @@ def ignore_cache_for(self, entities=None):
ndb.get_context().set_cache_policy(
lambda key: key.kind() not in entities)

@adapters.register_for('google:postgres')
@adapters.register_for('google:psycopg2')
class GooglePostgres(PostgrePsyco):
uploads_in_blob = True
drivers = ('psycopg2',)

def __init__(self, *args, **kwargs):
super(GooglePostgres, self).__init__(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion pydal/adapters/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _initialize_(self, do_connect):
if socket:
self.driver_args.update(
unix_socket=socket,
ser=user, passwd=password,
user=user, passwd=password,
charset=charset)
if db:
self.driver_args.update(db=db)
Expand Down
279 changes: 139 additions & 140 deletions pydal/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,151 +10,150 @@
pyodbc = None
couchdb = None
is_jdbc = False
else:
try:
from pysqlite2 import dbapi2 as sqlite2
DRIVERS['sqlite2'] = sqlite2
except ImportError:
pass

try:
from sqlite3 import dbapi2 as sqlite3
DRIVERS['sqlite3'] = sqlite3
except ImportError:
pass

try:
import pymysql
DRIVERS['pymysql'] = pymysql
except ImportError:
pass

try:
import MySQLdb
DRIVERS['MySQLdb'] = MySQLdb
except ImportError:
pass

try:
import mysql.connector as mysqlconnector
DRIVERS["mysqlconnector"] = mysqlconnector
except ImportError:
pass

try:
import psycopg2
from psycopg2.extensions import adapt as psycopg2_adapt
DRIVERS['psycopg2'] = psycopg2
except ImportError:
psycopg2_adapt = None

try:
import pg8000
DRIVERS['pg8000'] = pg8000
except ImportError:
pass

try:
import cx_Oracle
DRIVERS['cx_Oracle'] = cx_Oracle
except ImportError:
cx_Oracle = None

try:
import pyodbc
try:
from pysqlite2 import dbapi2 as sqlite2
DRIVERS['sqlite2'] = sqlite2
except ImportError:
pass

try:
from sqlite3 import dbapi2 as sqlite3
DRIVERS['sqlite3'] = sqlite3
except ImportError:
pass

try:
import pymysql
DRIVERS['pymysql'] = pymysql
except ImportError:
pass

try:
import MySQLdb
DRIVERS['MySQLdb'] = MySQLdb
except ImportError:
pass

try:
import mysql.connector as mysqlconnector
DRIVERS["mysqlconnector"] = mysqlconnector
except ImportError:
pass

try:
import psycopg2
from psycopg2.extensions import adapt as psycopg2_adapt
DRIVERS['psycopg2'] = psycopg2
except ImportError:
psycopg2_adapt = None

try:
import pg8000
DRIVERS['pg8000'] = pg8000
except ImportError:
pass

try:
import cx_Oracle
DRIVERS['cx_Oracle'] = cx_Oracle
except ImportError:
cx_Oracle = None

try:
import pyodbc
DRIVERS['pyodbc'] = pyodbc
#DRIVERS.append('DB2(pyodbc)')
#DRIVERS.append('Teradata(pyodbc)')
#DRIVERS.append('Ingres(pyodbc)')
except ImportError:
try:
import pypyodbc as pyodbc
DRIVERS['pyodbc'] = pyodbc
#DRIVERS.append('DB2(pyodbc)')
#DRIVERS.append('Teradata(pyodbc)')
#DRIVERS.append('Ingres(pyodbc)')
except ImportError:
try:
import pypyodbc as pyodbc
DRIVERS['pyodbc'] = pyodbc
except ImportError:
pyodbc = None

try:
import ibm_db_dbi
DRIVERS['ibm_db_dbi'] = ibm_db_dbi
except ImportError:
pass

try:
import Sybase
DRIVERS['Sybase'] = Sybase
except ImportError:
pass

try:
import kinterbasdb
DRIVERS['kinterbasdb'] = kinterbasdb
#DRIVERS.append('Firebird(kinterbasdb)')
except ImportError:
pass

try:
import fdb
DRIVERS['fdb'] = fdb
except ImportError:
pass

try:
import firebirdsql
DRIVERS['firebirdsql'] = firebirdsql
except ImportError:
pass

try:
import informixdb
#LOGGER.warning('Informix support is experimental')
DRIVERS['informixdb'] = informixdb
except ImportError:
pass

try:
import sapdb
DRIVERS['sapdb'] = sapdb
#LOGGER.warning('SAPDB support is experimental')
except ImportError:
pass

try:
import cubriddb
DRIVERS['cubriddb'] = cubriddb
#LOGGER.warning('Cubrid support is experimental')
except ImportError:
pass

try:
from com.ziclix.python.sql import zxJDBC
import java.sql
# Try sqlite jdbc driver from http://www.zentus.com/sqlitejdbc/
from org.sqlite import JDBC # required by java.sql; ensure we have it
zxJDBC_sqlite = java.sql.DriverManager
DRIVERS['zxJDBC'] = zxJDBC
#DRIVERS.append('SQLite(zxJDBC)')
#LOGGER.warning('zxJDBC support is experimental')
is_jdbc = True
except ImportError:
is_jdbc = False

try:
import couchdb
DRIVERS['couchdb'] = couchdb
except ImportError:
couchdb = None
pyodbc = None

try:
import ibm_db_dbi
DRIVERS['ibm_db_dbi'] = ibm_db_dbi
except ImportError:
pass
try:
import Sybase
DRIVERS['Sybase'] = Sybase
except ImportError:
pass

try:
import kinterbasdb
DRIVERS['kinterbasdb'] = kinterbasdb
#DRIVERS.append('Firebird(kinterbasdb)')
except ImportError:
pass

try:
import fdb
DRIVERS['fdb'] = fdb
except ImportError:
pass

try:
import firebirdsql
DRIVERS['firebirdsql'] = firebirdsql
except ImportError:
pass

try:
import informixdb
#LOGGER.warning('Informix support is experimental')
DRIVERS['informixdb'] = informixdb
except ImportError:
pass

try:
import sapdb
DRIVERS['sapdb'] = sapdb
#LOGGER.warning('SAPDB support is experimental')
except ImportError:
pass

try:
import cubriddb
DRIVERS['cubriddb'] = cubriddb
#LOGGER.warning('Cubrid support is experimental')
except ImportError:
pass

try:
from com.ziclix.python.sql import zxJDBC
import java.sql
# Try sqlite jdbc driver from http://www.zentus.com/sqlitejdbc/
from org.sqlite import JDBC # required by java.sql; ensure we have it
zxJDBC_sqlite = java.sql.DriverManager
DRIVERS['zxJDBC'] = zxJDBC
#DRIVERS.append('SQLite(zxJDBC)')
#LOGGER.warning('zxJDBC support is experimental')
is_jdbc = True
except ImportError:
is_jdbc = False

try:
import pymongo
DRIVERS['pymongo'] = pymongo
except:
pass
try:
import couchdb
DRIVERS['couchdb'] = couchdb
except ImportError:
couchdb = None

try:
import imaplib
DRIVERS['imaplib'] = imaplib
except:
pass
try:
import pymongo
DRIVERS['pymongo'] = pymongo
except:
pass

try:
import imaplib
DRIVERS['imaplib'] = imaplib
except:
pass


# for backward compatibility?
Expand Down

0 comments on commit 466a39f

Please sign in to comment.