first commit

This commit is contained in:
Senad Uka
2017-11-07 09:23:57 +01:00
commit 0eee92660a
356 changed files with 747259 additions and 0 deletions

0
helix/db/__init__.py Normal file
View File

17
helix/db/redis_manager.py Normal file
View File

@@ -0,0 +1,17 @@
import json
import redis
class RedisManager(object):
@staticmethod
def get_redis_connection(vcap_env, heroku_redis_url):
if vcap_env:
redis_env = json.loads(vcap_env)['rediscloud'][0]['credentials']
return redis.Redis(host=redis_env['hostname'],
port=int(redis_env['port']),
password=redis_env['password'])
elif heroku_redis_url:
return redis.Redis.from_url(heroku_redis_url)
else:
return redis.Redis(host='localhost', port=6379, db=0)

26
helix/db/sql_manager.py Normal file
View File

@@ -0,0 +1,26 @@
import sqlalchemy
from sqlalchemy.orm import sessionmaker
class SQLManager(object):
# Cache the database connection per application process.
# More properly, this should be kept in thread-local state (threading.local()), but should suffice.
# Each passed connection url will have its own pool.
engines = {}
@classmethod
def get_sql_session_maker(cls, heroku_postgres_url, should_echo=False, cache=True):
if not cache:
return sessionmaker(bind=cls.connect(heroku_postgres_url, should_echo=should_echo))()
else:
engine = cls.engines.setdefault(heroku_postgres_url,
cls.connect(heroku_postgres_url, should_echo=should_echo))
return sessionmaker(bind=engine)()
@staticmethod
def connect(heroku_postgres_url, should_echo=False):
if heroku_postgres_url:
return sqlalchemy.create_engine(heroku_postgres_url, echo=should_echo)
else:
return sqlalchemy.create_engine('postgres://pivotal:@localhost/pivotal', echo=True)