Lazy-load the primary keys.
1496
def pks(self):
        """"""
        if self._primary_keys is None:
            self._primary_keys = list(
                self.queryset.values_list('pk', flat=True))
        return self._primary_keys
1266218
def get_primary_key(self, table):
        """"""
        for column in self.get_schema(table):
            if len(column) > 3 and 'pri' in column[3].lower():
                return column[0]
939047
@Transactional(readOnly = true)
    public Object load(Object key) {
        List<T> results = getJdbcTemplate().query(
                getSelectSql(), getRowMapper(), getPrimaryKeyComponents(key));
        return results.size() == 0 ? null : results.get(0);
    }
66169
def from_dataframe(cls, name, df, indices, primary_key=None):
        """"""

        # ordered list (column_name, column_type) pairs
        column_types = []
        # which columns have nullable values
        nullable = set()

        # tag cached database by dataframe's number of rows and columns
        for column_name in df.columns:
            values = df[column_name]
            if values.isnull().any():
                nullable.add(column_name)
            column_db_type = db_type(values.dtype)
            column_types.append((column_name.replace(" ", "_"), column_db_type))

        def make_rows():
            return list(tuple(row) for row in df.values)

        return cls(
            name=name,
            column_types=column_types,
            make_rows=make_rows,
            indices=indices,
            nullable=nullable,
            primary_key=primary_key)
1312236
def drop_primary_key(self, table):
        """"""
        if self.get_primary_key(table):
            self.execute('ALTER TABLE {0} DROP PRIMARY KEY'.format(wrap(table)))
615660
@Override
    public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException
    {
        assert(table != null && !table.isEmpty());
        checkClosed();
        this.sysCatalog.setString(1, "PRIMARYKEYS");
        JDBC4ResultSet res = (JDBC4ResultSet) this.sysCatalog.executeQuery();
        VoltTable vtable = res.getVoltTable().clone(0);

        // Filter the primary keys based on table name
        while (res.next()) {
            if (res.getString("TABLE_NAME").equals(table)) {
                vtable.addRow(res.getRowData());
            }
        }
        return new JDBC4ResultSet(sysCatalog, vtable);
    }
1316237
def _load_dict_hierarchical(self, db_key: str) -> dict:
        """"""
        db_keys = self._db.keys(pattern=db_key + '*')
        my_dict = {}
        for _db_key in db_keys:
            if self._db.type(_db_key) == 'list':
                db_values = self._db.lrange(_db_key, 0, -1)
                for i, value in enumerate(db_values):
                    try:
                        db_values[i] = ast.literal_eval(value)
                    except SyntaxError:
                        pass
                    except ValueError:
                        pass
            else:  # self._db.type == 'hash'
                db_values = self._db.hgetall(_db_key)
                for _key, _value in db_values.items():
                    try:
                        db_values[_key] = ast.literal_eval(_value)
                    except SyntaxError:
                        pass
                    except ValueError:
                        pass
            my_dict = self._build_dict(my_dict, _db_key.split(':'),
                                       db_values)
        return my_dict[db_key]
98120
def loadColumns(self, records, columnName):
        
        try:
            for record in records:
                col = record.schema().column(columnName)
                if not col:
                    continue
                
                value = record.recordValue(col.name(), autoInflate=True)
                self.columnLoaded.emit(record, col.name(), wrapNone(value))
        
        except ConnectionLostError:
            self.connectionLost.emit()
        
        except Interruption:
            pass
675888
def get_primary_keys(conn, table: str, schema='public'):
    """"""

    query = """\
SELECT
  c.constraint_name AS pkey_constraint_name,
  c.column_name     AS column_name
FROM
  information_schema.key_column_usage AS c
  JOIN information_schema.table_constraints AS t
    ON t.constraint_name = c.constraint_name
       AND t.table_catalog = c.table_catalog
       AND t.table_schema = c.table_schema
       AND t.table_name = c.table_name
WHERE t.constraint_type = 'PRIMARY KEY'
  AND c.table_schema=%s
  AND c.table_name=%s
ORDER BY c.ordinal_position"""

    for record in select_dict(conn, query, params=(schema, table)):
        yield record['column_name']
1170366
private static void lazyInit() {
		if (components==null) {
			components = new HashSet<Component>();
			nonTerminalComps = new HashMap<Set<String>, Component>();
			nTerminalAminoAcids = new HashMap<Set<String>, Component>();
			cTerminalAminoAcids = new HashMap<Set<String>, Component>();
		}
	}
451777
private void loadFromResultSet(
		final Tuple resultset,
		final int i,
		final Object object,
		final String instanceEntityName,
		final org.hibernate.engine.spi.EntityKey key,
		final String rowIdAlias,
		final LockMode lockMode,
		final Loadable rootPersister,
		final SharedSessionContractImplementor session)
	throws HibernateException {

		final Serializable id = key.getIdentifier();

		// Get the persister for the _subclass_
		final OgmEntityPersister persister = (OgmEntityPersister) getFactory().getMetamodel().entityPersister( instanceEntityName );

		if ( log.isTraceEnabled() ) {
			log.trace(
					"Initializing object from ResultSet: " +
					MessageHelper.infoString( persister, id, getFactory() )
				);
		}

		//FIXME figure out what that means and what value should be set
		//boolean eagerPropertyFetch = isEagerPropertyFetchEnabled(i);
		boolean fetchAllPropertiesRequested = true;

		// add temp entry so that the next step is circular-reference
		// safe - only needed because some types don't take proper
		// advantage of two-phase-load (esp. components)
		TwoPhaseLoad.addUninitializedEntity(
				key,
				object,
				persister,
				lockMode,
				session
		);

		//TODO what to do with that in OGM
//		//This is not very nice (and quite slow):
//		final String[][] cols = persister == rootPersister ?
//				getEntityAliases()[i].getSuffixedPropertyAliases() :
//				getEntityAliases()[i].getSuffixedPropertyAliases(persister);

		final Object[] values = persister.hydrate(
				resultset,
				id,
				object,
				rootPersister,
				//cols,
				fetchAllPropertiesRequested,
				session
			);

		if ( persister.hasRowId() ) {
			throw new HibernateException( "Hibernate OGM does not support row id" );
		}
		final Object rowId = null;

		final AssociationType[] ownerAssociationTypes = getOwnerAssociationTypes();
		if ( ownerAssociationTypes != null && ownerAssociationTypes[i] != null ) {
			String ukName = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName();
			if ( ukName != null ) {
				final int index = ( (UniqueKeyLoadable) persister ).getPropertyIndex( ukName );
				final Type type = persister.getPropertyTypes()[index];

				// polymorphism not really handled completely correctly,
				// perhaps...well, actually its ok, assuming that the
				// entity name used in the lookup is the same as the
				// the one used here, which it will be

				EntityUniqueKey euk = new EntityUniqueKey(
						rootPersister.getEntityName(), //polymorphism comment above
						ukName,
						type.semiResolve( values[index], session, object ),
						type,
						persister.getEntityMode(),
						session.getFactory()
					);
				session.getPersistenceContext().addEntity( euk, object );
			}
		}

		TwoPhaseLoad.postHydrate(
				persister,
				id,
				values,
				rowId,
				object,
				lockMode,
				session
			);

		OgmEntityEntryState.getStateFor( session, object ).getTuplePointer().setTuple( resultset );
	}
363988
protected final void loadKeys(String key, String[] value) {
        String[] parsed = parseKey(key);

        if (parsed == null) {
            return;
        }

        if (!queryMap.containsKey(parsed[0])) {
            queryMap.put(parsed[0], new QueryParamsMap());
        }
        if (!parsed[1].isEmpty()) {
            queryMap.get(parsed[0]).loadKeys(parsed[1], value);
        } else {
            queryMap.get(parsed[0]).values = value.clone();
        }
    }
332612
public Map<Key, Object> loadRelatedEntities(String... propertyName) {
		EntityManager entityManager = EntityManagerFactory.getEntityManager();
		Class<J> persistentClass = (Class<J>) query.getClassMetadata().getPersistentClass();
		Set<Key> keys = Sets.newHashSet();
		for (String p : propertyName) {
			keys.addAll(Collections2.transform(data, new EntityToPropertyFunction(persistentClass, p)));
		}
		return entityManager.get(keys);
	}
441797
protected function loadData()
    {
        if (null === $this->data) {
            $this->statement->execute();
            $this->data = $this->statement->fetchAll(\PDO::FETCH_ASSOC);
        }
    }
1047972
def get_primary_key(model):
    """"""
    model = get_model(model)
    return (field.name for field in model._meta.fields if field.primary_key).next()
610652
protected function fill()
    {
        $this->primaryKeys = $this->blueprint->primaryKey();

        // Process columns
        foreach ($this->blueprint->columns() as $column) {
            $this->parseColumn($column);
        }

        if (! $this->loadRelations) {
            return;
        }

        foreach ($this->blueprint->relations() as $relation) {
            $model = $this->makeRelationModel($relation);
            $belongsTo = new BelongsTo($relation, $this, $model);
            $this->relations[$belongsTo->name()] = $belongsTo;
        }

        foreach ($this->factory->referencing($this) as $related) {
            $factory = new ReferenceFactory($related, $this);
            $references = $factory->make();
            foreach ($references as $reference) {
                $this->relations[$reference->name()] = $reference;
            }
        }
    }
720907
@Override
    public <TResult> Lazy<Map<String, TResult>> load(Class<TResult> clazz, Collection<String> ids) {
        return _session.lazyLoadInternal(clazz, ids.toArray(new String[0]), _includes.toArray(new String[0]), null);
    }