added heroku support
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
Usage: in web2py models/db.py
|
||||
|
||||
from gluon.contrib.heroku import get_db
|
||||
db = get_db()
|
||||
|
||||
"""
|
||||
import os
|
||||
from gluon import *
|
||||
from gluon.dal import ADAPTERS, UseDatabaseStoredFile,PostgreSQLAdapter
|
||||
|
||||
class HerokuPostgresAdapter(UseDatabaseStoredFile,PostgreSQLAdapter):
|
||||
drivers = ('psycopg2',)
|
||||
uploads_in_blob = True
|
||||
|
||||
ADAPTERS['postgres'] = HerokuPostgresAdapter
|
||||
|
||||
def get_db(name = None, pool_size=10):
|
||||
if not name:
|
||||
names = [n for n in os.environ.keys()
|
||||
if n[:18]+n[-4:]=='HEROKU_POSTGRESQL__URL']
|
||||
if names:
|
||||
name = names[0]
|
||||
if name:
|
||||
db = DAL(os.environ[name], pool_size=pool_size)
|
||||
current.session.connect(current.request, current.response, db=db)
|
||||
else:
|
||||
db = DAL('sqlite://heroku.test.sqlite')
|
||||
return db
|
||||
+7
-3
@@ -3964,13 +3964,17 @@ class DatabaseStoredFile:
|
||||
return self.db._adapter.escape(obj)
|
||||
|
||||
def __init__(self,db,filename,mode):
|
||||
if db._adapter.dbengine != 'mysql':
|
||||
raise RuntimeError("only MySQL can store metadata .table files in database for now")
|
||||
if not db._adapter.dbengine in ('mysql', 'postgres'):
|
||||
raise RuntimeError("only MySQL/Postgres can store metadata .table files in database for now")
|
||||
self.db = db
|
||||
self.filename = filename
|
||||
self.mode = mode
|
||||
if not self.web2py_filesystem:
|
||||
self.db.executesql("CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content LONGTEXT, PRIMARY KEY(path) ) ENGINE=InnoDB;")
|
||||
if db._adapter.dbengine == 'mysql':
|
||||
sql = "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content LONGTEXT, PRIMARY KEY(path) ) ENGINE=InnoDB;"
|
||||
elif db._adapter.dbengine == 'postgres':
|
||||
sql = "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content TEXT, PRIMARY KEY(path));"
|
||||
self.db.executesql(sql)
|
||||
DatabaseStoredFile.web2py_filesystem = True
|
||||
self.p=0
|
||||
self.data = ''
|
||||
|
||||
Reference in New Issue
Block a user