コード例 #1
0
ファイル: db.py プロジェクト: syed/instatnt-press
def connect_to_db(config):

    if request.env.web2py_runtime_gae:

        from gluon.contrib.gae_memcache import MemcacheClient
        from gluon.contrib.memdb import MEMDB
        cache.memcache = MemcacheClient(request)
        cache.ram = cache.disk = cache.memcache

        db = DAL('gae')
        session.connect(request, response, MEMDB(cache.memcache))

    else:

        db = DAL(config.connect_uri)

    return db
コード例 #2
0
 def __init__(self, request):
     """
     Args:
         request: the global request object
     """
     # GAE will have a special caching
     if have_settings and settings.global_settings.web2py_runtime_gae:
         from gluon.contrib.gae_memcache import MemcacheClient
         self.ram = self.disk = MemcacheClient(request)
     else:
         # Otherwise use ram (and try also disk)
         self.ram = CacheInRam(request)
         try:
             self.disk = CacheOnDisk(request)
         except IOError:
             logger.warning('no cache.disk (IOError)')
         except AttributeError:
             # normally not expected anymore, as GAE has already
             # been accounted for
             logger.warning('no cache.disk (AttributeError)')
コード例 #3
0
ファイル: 10_config.py プロジェクト: SealWorks/w2p_apps

appconfig = AppConfig(reload=True)


if request.env.web2py_runtime_gae:
    # ---------------------------------------------------------------------
    # connect to Google BigTable (optional 'google:datastore://namespace')
    # ---------------------------------------------------------------------
    db = DAL('google:datastore+ndb', lazy_tables=True)
    # ---------------------------------------------------------------------
    # store sessions and tickets in Memcache
    # ---------------------------------------------------------------------
    from gluon.contrib.gae_memcache import MemcacheClient
    from gluon.contrib.memdb import MEMDB
    cache.memcache = MemcacheClient(request)
    cache.ram = cache.disk = cache.memcache
    session.connect(request, response, db=MEMDB(cache.memcache.client))
else:
    # ---------------------------------------------------------------------
    # if NOT running on Google App Engine use SQLite or other DB
    # ---------------------------------------------------------------------
    db = DAL(appconfig.get('db.uri'),
             pool_size=appconfig.get('db.pool_site'),
             migrate_enabled=appconfig.get('db.migrate'),
             check_reserved=appconfig.get('db.migrate') and ['all'] or None,
             lazy_tables=appconfig.get('db.lazy'))


# host names must be a list of allowed host names (glob syntax allowed)
auth = Auth(db, host_names=appconfig.get('host.names'))