Return repository model from database.
512710
def repo_model(self):
        """"""
        return Repository.query.filter_by(
            user_id=self.event.user_id,
            github_id=self.repository['id'],
        ).one()
1033757
function () {
                var db = this.__db;
                if (!db) {
                    db = this.__db = patio.defaultDatabase;
                }
                if (!db) {
                    throw new ModelError("patio has not been connected to a database");
                }
                return db;
            }
1226279
def db(self):
        """"""
        if self._db is None:
            if self.tcex.default_args.tc_playbook_db_type == 'Redis':
                from .tcex_redis import TcExRedis

                self._db = TcExRedis(
                    self.tcex.default_args.tc_playbook_db_path,
                    self.tcex.default_args.tc_playbook_db_port,
                    self.tcex.default_args.tc_playbook_db_context,
                )
            elif self.tcex.default_args.tc_playbook_db_type == 'TCKeyValueAPI':
                from .tcex_key_value import TcExKeyValue

                self._db = TcExKeyValue(self.tcex)
            else:
                err = u'Invalid DB Type: ({})'.format(self.tcex.default_args.tc_playbook_db_type)
                raise RuntimeError(err)
        return self._db
118205
def Model(self):
        """"""
        Model_ = self.app.config['PEEWEE_MODELS_CLASS']
        meta_params = {'database': self.database}
        if self.slaves and self.app.config['PEEWEE_USE_READ_SLAVES']:
            meta_params['read_slaves'] = self.slaves

        Meta = type('Meta', (), meta_params)
        return type('Model', (Model_,), {'Meta': Meta})
415945
def database(key='default', slave=False):
    
    if slave:
        key += '.slave'
        return choice(__db[key])
    return __db.get(key)
700368
def import_model(self, name, path="floyd.db.models"):
    """"""
    if name in self._model_cache:
      return self._model_cache[name]
  
    try:
      model = getattr(__import__(path, None, None, [name]), name)
      self._model_cache[name] = model
    except ImportError:
      return False
    return model
1111081
public function findOne(Repository $repository = null): Model
    {
        if (!$repository && !($repository = $this->repository)) {
            throw new \RuntimeException('The current Query object is not tied to any Repository');
        }

        return $repository->findOne($this->compileParameters());
    }
984740
def get_repository(self):
        
        if self._lookup_session is None:
            mgr = get_provider_manager('REPOSITORY', runtime=self._runtime, proxy=self._proxy)
            self._lookup_session = mgr.get_repository_lookup_session(proxy=getattr(self, "_proxy", None))
        return self._lookup_session.get_repository(Id(self._my_map['id']))
722720
def create_repository(self):
        """"""
        repo = repository.Repository(
            self.repository_config['repository'],
            self.username,
            self.password,
            self.disable_progress_bar
        )
        repo.set_certificate_authority(self.cacert)
        repo.set_client_certificate(self.client_cert)
        return repo
1296894
def find_model_by_table_name(name):
    """"""

    for model in ModelBase._decl_class_registry.values():
        if hasattr(model, '__table__') and model.__table__.fullname == name:
            return model
    return None
521470
private function find($id): ?Model
    {
        try {
            return $this->repository->findOrFail($id);
        } catch (ModelNotFoundException $exception) {
            return null;
        }
    }
132450
def connect_db(Repo, database=":memory:"):
        
        Repo.db = sqlite3.connect(database,
                                  detect_types=sqlite3.PARSE_DECLTYPES)
        return Repo.db
14027
def load_model(path):
    """"""
    abspath = find_data(path)
    cached = _model_cache.get(abspath)
    if cached is not None:
        log.debug('Using cached copy of %s' % path)
        return cached
    log.debug('Loading model %s' % path)
    try:
        with io.open(abspath, 'rb') as f:
            model = six.moves.cPickle.load(f)
    except IOError:
        raise ModelNotFoundError('Could not load %s. Have you run `cde data download`?' % path)
    _model_cache[abspath] = model
    return model
438785
def get_collection(self, namespace):
        """"""
        database, coll = namespace.split(".", 1)
        return self.primary_client[database][coll]
431019
def versioning_models_registered(manager, base):
    """"""
    declared_models = base._decl_class_registry.keys()
    return all(versioning_model_classname(manager, c) in declared_models
               for c in manager.pending_classes)
84539
def all(self):
        
        logger.debug(f'Query `{self.__class__.__name__}` objects with filters {self}')

        # Destroy any cached results
        self._result_cache = None

        # Fetch Model class and connected repository from Repository Factory
        model_cls = repo_factory.get_model(self._entity_cls)
        repository = repo_factory.get_repository(self._entity_cls)

        # order_by clause must be list of keys
        order_by = self._entity_cls.meta_.order_by if not self._order_by else self._order_by

        # Call the read method of the repository
        results = repository.filter(self._criteria, self._offset, self._limit, order_by)

        # Convert the returned results to entity and return it
        entity_items = []
        for item in results.items:
            entity = model_cls.to_entity(item)
            entity.state_.mark_retrieved()
            entity_items.append(entity)
        results.items = entity_items

        # Cache results
        self._result_cache = results

        return results
1268575
def get_object(self):
        """"""
        return self.content_type.model_class().objects.get(uid = self.uid)