Get a document from the database by key

@param {String} key
@return {Promise}
505692
function(key) {
      var that = this;

      if (!this._key || !key) {
        return Promise.reject(new Error('No unique key specified'));
      }

      var props = {};
      props[this._key] = key;

      return this._dbApi.find(props).then(function(docs) {
        return that._readDoc(docs[0]);
      });
    }
199263
function get($key, $default = null)
    {
        if ( $r = parent::get($key, $default) )
            return $r;


        $realm = $this->getRealm();

        try {

            $sql = "SELECT * FROM `KVStore` WHERE `realm` = '$realm' and `key` = '$key';";

            $stm = $this->pdo->prepare($sql);
            $stm->execute();
            $stm->setFetchMode(\PDO::FETCH_ASSOC);

            $document = $stm->fetch();

        } catch (\Exception $e) {
            throw new exReadError($e->getMessage(), $e->getCode(), $e);
        }

        $r = (false === $document)
            ? $default
            : $this->getDataInterchange()->retrieveBackward($document['value']);


        parent::set($key, $r);
        return $r;
    }
696997
function _get(key){
	var ret = null;

	// Pull from cache or re-read from fs.
	//console.log('key: ' + key)
	//console.log('use_zcache_p: ' + use_zcache_p)
	if( use_zcache_p ){
	    ret = zcache[key];
	}else{
	    ret = afs.read_file(path_cache[key]);
	}

	return ret;
    }
2548
def get(self, key):
        
        return self._object_class(json.loads(self._db[key]))
639259
public final Promise get(String key) {
		byte[] binaryKey = key.getBytes(StandardCharsets.UTF_8);
		if (client != null) {
			return new Promise(client.get(binaryKey));
		}
		if (clusteredClient != null) {
			return new Promise(clusteredClient.get(binaryKey));
		}
		return Promise.resolve();
	}
715609
public T get(String key) {
        rlock.lock();
        try {
            return map.get(key);
        } finally {
            rlock.unlock();
        }
    }
708613
function &get($key, $raw = false) {
		// handle virtual fields
		if (isset($this->vFields[$key])) {
			$out = (is_callable($this->vFields[$key]))
				? call_user_func($this->vFields[$key], $this) : $this->vFields[$key];
			return $out;
		}
		$fields = $this->fieldConf;
		$id = $this->primary;
		if ($key == '_id' && $this->dbsType == 'sql')
			$key = $id;
		if ($this->whitelist && !in_array($key,$this->whitelist)) {
			$out = null;
			return $out;
		}
		if ($raw) {
			$out = $this->exists($key) ? $this->mapper->{$key} : NULL;
			if ($this->dbsType == 'mongo' && !$this->db->legacy() && $out instanceof \MongoDB\Model\BSONArray)
				$out = (array) $out;
			return $out;
		}
		if (!empty($fields) && isset($fields[$key]) && is_array($fields[$key])
			&& !array_key_exists($key,$this->fieldsCache)) {
			// load relations
			if (isset($fields[$key]['belongs-to-one'])) {
				// one-to-X, bidirectional, direct way
				if (!$this->exists($key) || is_null($this->mapper->{$key}))
					$this->fieldsCache[$key] = null;
				else {
					// get config for this field
					$relConf = $fields[$key]['belongs-to-one'];
					// fetch related model
					$rel = $this->getRelFromConf($relConf,$key);
					// am i part of a result collection?
					if ($cx = $this->getCollection()) {
						// does the collection has cached results for this key?
						if (!$cx->hasRelSet($key)) {
							// build the cache, find all values of current key
							$relKeys = array_unique($cx->getAll($key,true));
							// find related models
							$crit = array($relConf[1].' IN ?', $relKeys);
							$relSet = $rel->find($this->mergeWithRelFilter($key, $crit),
								$this->getRelFilterOption($key),$this->_ttl);
							// cache relSet, sorted by ID
							$cx->setRelSet($key, $relSet ? $relSet->getBy($relConf[1]) : NULL);
						}
						// get a subset of the preloaded set
						$result = $cx->getSubset($key,(string) $this->get($key,true));
						$this->fieldsCache[$key] = $result ? $result[0] : NULL;
					} else {
						$crit = array($relConf[1].' = ?', $this->get($key, true));
						$crit = $this->mergeWithRelFilter($key, $crit);
						$this->fieldsCache[$key] = $rel->findone($crit,
							$this->getRelFilterOption($key),$this->_ttl);
					}
				}
			}
			elseif (($type = isset($fields[$key]['has-one']))
				|| isset($fields[$key]['has-many'])) {
				$type = $type ? 'has-one' : 'has-many';
				$fromConf = $fields[$key][$type];
				if (!is_array($fromConf))
					trigger_error(sprintf(self::E_REL_CONF_INC, $key),E_USER_ERROR);
				$rel = $this->getRelInstance($fromConf[0],null,$key,true);
				$relFieldConf = $rel->getFieldConfiguration();
				$relType = isset($relFieldConf[$fromConf[1]]['belongs-to-one']) ?
					'belongs-to-one' : 'has-many';
				// one-to-*, bidirectional, inverse way
				if ($relType == 'belongs-to-one') {
					$toConf = $relFieldConf[$fromConf[1]]['belongs-to-one'];
					if (!is_array($toConf))
						$toConf = array($toConf, $id);
					if ($toConf[1] != $id && (!$this->exists($toConf[1])
							|| is_null($this->mapper->get($toConf[1]))))
						$this->fieldsCache[$key] = null;
					elseif ($cx=$this->getCollection()) {
						// part of a result set
						if (!$cx->hasRelSet($key)) {
							// emit eager loading
							$relKeys = $cx->getAll($toConf[1],true);
							$crit = array($fromConf[1].' IN ?', $relKeys);
							$relSet = $rel->find($this->mergeWithRelFilter($key,$crit),
								$this->getRelFilterOption($key),$this->_ttl);
							$cx->setRelSet($key, $relSet ? $relSet->getBy($fromConf[1],true) : NULL);
						}
						$result = $cx->getSubset($key, array($this->get($toConf[1])));
						$this->fieldsCache[$key] = $result ? (($type == 'has-one')
							? $result[0][0] : CortexCollection::factory($result[0])) : NULL;
					}	// no collection
					elseif (($val=$this->getRaw($toConf[1])) && $val!==NULL) {
						$crit=[$fromConf[1].' = ?',$val];
						$crit=$this->mergeWithRelFilter($key,$crit);
						$opt=$this->getRelFilterOption($key);
						$this->fieldsCache[$key]=(($type=='has-one')
							?$rel->findone($crit,$opt,$this->_ttl)
							:$rel->find($crit,$opt,$this->_ttl))?:NULL;
					} else
						$this->fieldsCache[$key] = NULL;
				}
				// many-to-many, bidirectional
				elseif ($relType == 'has-many') {
					$toConf = $relFieldConf[$fromConf[1]]['has-many'];
					$mmTable = $this->mmTable($fromConf,$key,$toConf);
					// create mm table mapper
					if (!$this->get($id,true)) {
						$this->fieldsCache[$key] = null;
						return $this->fieldsCache[$key];
					}
					$id = $toConf['relPK'];
					$rel = $this->getRelInstance(null,array('db'=>$this->db,'table'=>$mmTable));
					if ($cx = $this->getCollection()) {
						if (!$cx->hasRelSet($key)) {
							// get IDs of all results
							$relKeys = $cx->getAll($id,true);
							// get all pivot IDs
							$filter = [$fromConf['relField'].' IN ?',$relKeys];
							if ($fromConf['isSelf']) {
								$filter[0].= ' OR '.$fromConf['relField'].'_ref IN ?';
								$filter[] = $relKeys;
							}
							$mmRes = $rel->find($filter,null,$this->_ttl);
							if (!$mmRes)
								$cx->setRelSet($key, NULL);
							else {
								$pivotRel = array();
								$pivotKeys = array();
								foreach($mmRes as $model) {
									$val = $model->get($key,true);
									if ($fromConf['isSelf']) {
										$refVal = $model->get($fromConf['relField'].'_ref',true);
										$pivotRel[(string) $refVal][] = $val;
										$pivotRel[(string) $val][] = $refVal;
										$pivotKeys[] = $val;
										$pivotKeys[] = $refVal;
									} else {
										$pivotRel[ (string) $model->get($fromConf['relField'])][] = $val;
										$pivotKeys[] = $val;
									}
								}
								// cache pivot keys
								$cx->setRelSet($key.'_pivot', $pivotRel);
								// preload all rels
								$pivotKeys = array_unique($pivotKeys);
								$fRel = $this->getRelInstance($fromConf[0],null,$key,true);
								$crit = array($id.' IN ?', $pivotKeys);
								$relSet = $fRel->find($this->mergeWithRelFilter($key, $crit),
									$this->getRelFilterOption($key),$this->_ttl);
								$cx->setRelSet($key, $relSet ? $relSet->getBy($id) : NULL);
								unset($fRel);
							}
						}
						// fetch subset from preloaded rels using cached pivot keys
						$fkeys = $cx->getSubset($key.'_pivot', array($this->get($id)));
						$this->fieldsCache[$key] = $fkeys ?
							CortexCollection::factory($cx->getSubset($key, $fkeys[0])) : NULL;
					} // no collection
					else {
						// find foreign keys
						$fId=$this->get($fromConf['localKey'],true);
						$filter = [$fromConf['relField'].' = ?',$fId];
						if ($fromConf['isSelf']) {
							$filter = [$fromConf['relField'].' = ?',$fId];
							$filter[0].= ' OR '.$fromConf['relField'].'_ref = ?';
							$filter[] = $filter[1];
						}
						$results = $rel->find($filter,null,$this->_ttl);
						if (!$results)
							$this->fieldsCache[$key] = NULL;
						else {
							$fkeys = $results->getAll($key,true);
							if ($fromConf['isSelf']) {
								// merge both rel sides and remove itself
								$fkeys = array_diff(array_merge($fkeys,
									$results->getAll($key.'_ref',true)),[$fId]);
							}
							// create foreign table mapper
							unset($rel);
							$rel = $this->getRelInstance($fromConf[0],null,$key,true);
							// load foreign models
							$filter = array($fromConf['relPK'].' IN ?', $fkeys);
							$filter = $this->mergeWithRelFilter($key, $filter);
							$this->fieldsCache[$key] = $rel->find($filter,
								$this->getRelFilterOption($key),$this->_ttl);
						}
					}
				}
			}
			elseif (isset($fields[$key]['belongs-to-many'])) {
				// many-to-many, unidirectional
				$fields[$key]['type'] = self::DT_JSON;
				$result = $this->getRaw($key);
				if ($this->dbsType == 'sql')
					$result = json_decode($result, true);
				if (!is_array($result))
					$this->fieldsCache[$key] = $result;
				else {
					// create foreign table mapper
					$relConf = $fields[$key]['belongs-to-many'];
					$rel = $this->getRelFromConf($relConf,$key);
					$fkeys = array();
					foreach ($result as $el)
						$fkeys[] = (is_int($el)||ctype_digit($el))?(int)$el:(string)$el;
					// if part of a result set
					if ($cx = $this->getCollection()) {
						if (!$cx->hasRelSet($key)) {
							// find all keys
							$relKeys = ($cx->getAll($key,true));
							if ($this->dbsType == 'sql'){
								foreach ($relKeys as &$val) {
									$val = substr($val, 1, -1);
									unset($val);
								}
								$relKeys = json_decode('['.implode(',',$relKeys).']');
							} else
								$relKeys = call_user_func_array('array_merge', $relKeys);
							// get related models
							if (!empty($relKeys)) {
								$crit = array($relConf[1].' IN ?', array_unique($relKeys));
								$relSet = $rel->find($this->mergeWithRelFilter($key, $crit),
								$this->getRelFilterOption($key),$this->_ttl);
								// cache relSet, sorted by ID
								$cx->setRelSet($key, $relSet ? $relSet->getBy($relConf[1]) : NULL);
							} else
								$cx->setRelSet($key, NULL);
						}
						// get a subset of the preloaded set
						$this->fieldsCache[$key] = CortexCollection::factory($cx->getSubset($key, $fkeys));
					} else {
						// load foreign models
						$filter = array($relConf[1].' IN ?', $fkeys);
						$filter = $this->mergeWithRelFilter($key, $filter);
						$this->fieldsCache[$key] = $rel->find($filter,
							$this->getRelFilterOption($key),$this->_ttl);
					}
				}
			}
			// resolve array fields
			elseif (isset($fields[$key]['type'])) {
				if ($this->dbsType == 'sql') {
					if ($fields[$key]['type'] == self::DT_SERIALIZED)
						$this->fieldsCache[$key] = unserialize($this->mapper->{$key});
					elseif ($fields[$key]['type'] == self::DT_JSON)
						$this->fieldsCache[$key] = json_decode($this->mapper->{$key},true);
				}
				if ($this->exists($key) && preg_match('/BOOL/i',$fields[$key]['type'])) {
					$this->fieldsCache[$key] = (bool) $this->mapper->{$key};
				}
			}
		}
		// fetch cached value, if existing
		// TODO: fix array key reference editing, #71
//		if (array_key_exists($key,$this->fieldsCache))
//			$val = $this->fieldsCache[$key];
//		elseif ($this->exists($key)) {
//			$val =& $this->mapper->{$key};
//		} else
//			$val = NULL;
		$val = array_key_exists($key,$this->fieldsCache) ? $this->fieldsCache[$key]
			: (($this->exists($key)) ? $this->mapper->{$key} : null);
		if ($this->dbsType == 'mongo' && (($this->db->legacy() && $val instanceof \MongoId) ||
				(!$this->db->legacy() && $val instanceof \MongoDB\BSON\ObjectId))) {
			// conversion to string makes further processing in template, etc. much easier
			$val = (string) $val;
		}
		// custom getter
		$out = $this->emit('get_'.$key, $val);
		return $out;
	}
608141
function( key ) {

    if( this.data[ key ] == null ) {
      return this.data[ key ]
    }

    if( Array.isArray( this.data[ key ] ) ) {
      return this.data[ key ].map( function( prop ) {
        return prop.clone()
      })
    } else {
      return this.data[ key ].clone()
    }

  }
515651
function (key) {
            var self = this, _queryMap;
            parseQuery(self);
            _queryMap = self._queryMap;
            if (key) {
                return _queryMap[key];
            } else {
                return _queryMap;
            }
        }
260709
function get(key) {
    var entry = strong.getEntry(validate(this, MAP), key);
    return entry && entry.v;
  }
582602
function get (key, def) {
  if (Array.isArray(key)) {
    return AsyncStorage.multiGet(key)
      .then((values) => values.map(([_, value]) => {
        return useDefault(def, value) ? def : parse(value)
      }))
      .then(results => Promise.all(results))
  }

  return AsyncStorage.getItem(key).then(value => useDefault(def, value) ? def : parse(value))
}
591437
async function take(key) {
    const previousLocks = LOCKS_MAP.get(key) || [];
    let locksLength = previousLocks.length;

    log('debug', `Taking the lock on ${key} (queue length was ${locksLength})`);

    let release;

    const newLock = {
      releasePromise: new Promise(async (resolve, reject) => {
        release = resolve;

        if (LOCK_TIMEOUT !== Infinity) {
          await delay.create(LOCK_TIMEOUT);

          reject(new YError('E_LOCK_TIMEOUT'));
        }
      }),
      release,
    };

    previousLocks.push(newLock);
    locksLength++;

    if (locksLength > 1) {
      await previousLocks[locksLength - 1].releasePromise;
    } else {
      LOCKS_MAP.set(key, previousLocks);
    }
  }
490772
function getItem$2(key, callback) {
    var self = this;

    key = normalizeKey(key);

    var promise = self.ready().then(function () {
        var dbInfo = self._dbInfo;
        var result = localStorage.getItem(dbInfo.keyPrefix + key);

        // If a result was found, parse it from the serialized
        // string into a JS object. If result isn't truthy, the key
        // is likely undefined and we'll pass it straight to the
        // callback.
        if (result) {
            result = dbInfo.serializer.deserialize(result);
        }

        return result;
    });

    executeCallback(promise, callback);
    return promise;
}
969294
function get(key) {
  return redis.get(key)
    .then(data => {
      if (isUri(key)) return data;
      return JSON.parse(data); // Parse non-uri data to match Postgres
    })
    .catch(() => postgres.get(key));
}
1240700
function get(key, cb) {
  return type(key) != 'array'
    ? localForage.getItem(key).then(wrap(cb, true), cb)
    : Promise.all(key.map(getSubkey)).then(wrap(cb, true), cb);

  function getSubkey(key) {
    return get(key, function() {}); // noob function to prevent logs
  }
}
191677
function (key) {
      if (key === undefined) {
        that.push({
          key: 'DOCUMENT' + sep + docId + sep,
          lastPass: true
        })
        return end()
      }
      that.options.indexes.get(key, function (err, val) {
        if (!err) {
          that.push({
            key: key,
            value: val
          })
        }
        pushValue(docFields[i++])
      })
    }
379153
def get(self, key, *, encoding=_NOTSET):
        """"""
        return self.execute(b'GET', key, encoding=encoding)