src/util/loader_ex.js
async function retrieveEntityByAttribute(
    entitySet,
    componentID,
    attribute,
    value
) {
    // Log.debug('[retrieveEntityByAttribute]', componentID, 'where', attribute, 'equals', value);
    const query = Q => [
        Q.all(componentID).where(Q.attr(attribute).equals(value)),
        Q.limit(1)
    ];

    if (entitySet.isAsync) {
        const existing = await entitySet.query(query, { debug: false });

        // Log.debug('[retrieveEntityByAttribute]', entityToString( existing));
        if (existing.size() === 1) {
            return existing.at(0);
        }

        return null;
    } else {
        return Promise.resolve(true).then(() => {
            const existing = entitySet.query(query);
            // Log.debug('[retrieveEntityByAttribute]', 'query result', existing.size(), entityToString(existing), componentID, attribute, value );
            if (existing.size() === 1) {
                return existing.at(0);
            }
            return null;
        });
    }
}
async function retrieveEntityByAttribute(
    entitySet,
    componentID,
    attribute,
    value
) {
    // Log.debug('[retrieveEntityByAttribute]', componentID, 'where', attribute, 'equals', value);
    const query = Q => [
        Q.all(componentID).where(Q.attr(attribute).equals(value)),
        Q.limit(1)
    ];

    if (entitySet.isAsync) {
        const existing = await entitySet.query(query, { debug: false });

        // Log.debug('[retrieveEntityByAttribute]', entityToString( existing));
        if (existing.size() === 1) {
            return existing.at(0);
        }

        return null;
    } else {
        return Promise.resolve(true).then(() => {
            const existing = entitySet.query(query);
            // Log.debug('[retrieveEntityByAttribute]', 'query result', existing.size(), entityToString(existing), componentID, attribute, value );
            if (existing.size() === 1) {
                return existing.at(0);
            }
            return null;
        });
    }
}
async function retrieveEntityByAttribute ( entitySet , componentID , attribute , value ) { // Log.debug('[retrieveEntityByAttribute]', componentID, 'where', attribute, 'equals', value); const query = Q => [ Q . all ( componentID ) . where ( Q . attr ( attribute ) . equals ( value ) ) , Q . limit ( 1 ) ] ; if ( entitySet . isAsync ) { const existing = await entitySet . query ( query , { debug : false } ) ; // Log.debug('[retrieveEntityByAttribute]', entityToString( existing)); if ( existing . size ( ) === 1 ) { return existing . at ( 0 ) ; } return null ; } else { return Promise . resolve ( true ) . then ( ( ) => { const existing = entitySet . query ( query ) ; // Log.debug('[retrieveEntityByAttribute]', 'query result', existing.size(), entityToString(existing), componentID, attribute, value ); if ( existing . size ( ) === 1 ) { return existing . at ( 0 ) ; } return null ; } ) ; } }
Retrieves the first entity which has the specified component attribute value
Retrieves the first entity which has the specified component attribute value