def uri_from_config(config=None): if config is None or config.adapter is None: config = sdict(adapter="sqlite", host="dummy.db") if config.adapter == "<zombie>": return config.adapter if config.adapter == "sqlite" and config.host == "memory": return config.adapter+":"+config.host uri = config.adapter+"://" if config.user: uri = uri+config.user+":"+config.password+"@" uri = uri+config.host if config.database: uri += "/"+config.database return uri
def __init__(self, uri, config=sdict(), pool_size=0, folder=None, **kwargs): # self.logger = app.log # config = config or app.config.db config = config if not config.uri: config.uri = self.uri_from_config(config) self.config = config #: load config data kwargs['check_reserved'] = config.check_reserved or \ kwargs.get('check_reserved', None) kwargs['migrate'] = config.migrate or kwargs.get('migrate', True) kwargs['fake_migrate'] = config.fake_migrate or \ kwargs.get('fake_migrate', False) kwargs['fake_migrate_all'] = config.fake_migrate_all or \ kwargs.get('fake_migrate_all', False) kwargs['driver_args'] = config.driver_args or \ kwargs.get('driver_args', None) kwargs['adapter_args'] = config.adapter_args or \ kwargs.get('adapter_args', None) #: set directory folder = folder or current.request.env.web2py_path+'/applications/'+current.request.application+'/databases' # folder = os.path.join(app.root_path, folder) if not os.path.exists(folder): os.mkdir(folder) #: finally setup pyDAL instance self.serializers = {'json': _custom_json, 'xml': xml} # self.validators_method = _default_validators self.uuid = lambda x: _uuid() self.representers = { 'rows_render': sqlhtml.represent, 'rows_xml': sqlhtml.SQLTABLE } self.Field = Field self.Table = Table super(DAL, self).__init__(uri, pool_size, folder, **kwargs)
def _DAL_unpickler(db_uid): fake_app_obj = sdict(config=sdict(db=sdict())) fake_app_obj.config.db.adapter = '<zombie>' return DAL(fake_app_obj, db_uid=db_uid)