def config(module, server, port=None, db=None, replset=None, params=None): ''' Configure a data access module. ''' assert server and db, 'Either "server" or "db" may not be None.' params = {} if params is None else params conn = connect(server, port=port, replset=replset) module.DB = conn[db] module.IDS = IncrementalId(module.DB) if hasattr(module, 'INDEXES'): ensure_indexes(module, module.INDEXES)
def config(module, servers, replset=None): assert servers is not None and type(servers) is dict, 'servers must be a dict.' name = module.__name__ DBS[name] = ConnectionPool() IDS[name] = ConnectionPool() for key, value in servers.items(): repl = None if replset is not None and type(replset) is dict and key in replset: repl = replset[key] conn = connect(value['server'], port=value['port'], replset=repl) # module name and locale as key to manage connections DBS[name][key] = conn[value['db']] IDS[name][key] = IncrementalId(DBS[name][key]) # index and save js func if hasattr(module, 'INDEXES'): ensure_indexes(name, module, module.INDEXES) if hasattr(module, 'JS_FUNC'): save_js_funcs(name, module, module.JS_FUNC)
def config(module, servers, replset=None): assert servers is not None and type( servers) is dict, 'servers must be a dict.' name = module.__name__ DBS[name] = ConnectionPool() IDS[name] = ConnectionPool() for key, value in servers.items(): repl = None if replset is not None and type(replset) is dict and key in replset: repl = replset[key] conn = connect(value['server'], port=value['port'], replset=repl) # module name and locale as key to manage connections DBS[name][key] = conn[value['db']] IDS[name][key] = IncrementalId(DBS[name][key]) # index and save js func if hasattr(module, 'INDEXES'): ensure_indexes(name, module, module.INDEXES) if hasattr(module, 'JS_FUNC'): save_js_funcs(name, module, module.JS_FUNC)