Пример #1
0
    def _Get(self, key):
        app_kind, _, k = self._GetEntityLocation(key)

        try:
            stored_entity = self.__entities_by_kind[app_kind][k]
            return datastore_stub_util.LoadRecord(stored_entity.record)

        except KeyError:
            pass
Пример #2
0
 def _Get(self, key):
   conn = self._GetConnection()
   try:
     prefix = self._GetTablePrefix(key)
     c = conn.execute(
         'SELECT entity FROM "%s!Entities" WHERE __path__ = ?' % (prefix,),
         (self.__EncodeIndexPB(key.path()),))
     row = c.fetchone()
     if row:
       entity = entity_pb.EntityProto()
       entity.ParseFromString(row[0])
       record = datastore_stub_util._FromStorageEntity(entity)
       return datastore_stub_util.LoadRecord(record)
   finally:
     self._ReleaseConnection(conn)
Пример #3
0
def _DedupingEntityGenerator(cursor):
  """Generator that removes duplicate entities from the results.

  Generate datastore entities from a cursor, skipping the duplicates

  Args:
    cursor: a SQLite3.Cursor or subclass.

  Yields:
    Entities that do not share a key.
  """
  seen = set()
  for row in cursor:
    row_key, row_entity = row[:2]
    encoded_row_key = str(row_key)
    if encoded_row_key in seen:
      continue

    seen.add(encoded_row_key)
    storage_entity = entity_pb.EntityProto(row_entity)
    record = datastore_stub_util._FromStorageEntity(storage_entity)
    record = datastore_stub_util.LoadRecord(record)
    yield record