You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Postgresql Loader use dataloader to batch sql queries * @flow */importtype{TableSinglePrimaryKey}from'../../TypeDefinition';functionindexResults(results,indexField,cacheKeyFn=key=>key){constindexedResults=newMap();results.forEach(res=>{indexedResults.set(cacheKeyFn(res[indexField]),res);});returnindexedResults;}functionnormalizeResults(keys,indexField,cacheKeyFn=key=>key){returnresults=>{constindexedResults=indexResults(results,indexField,cacheKeyFn);returnkeys.map(val=>indexedResults.get(cacheKeyFn(val))||null);//new Error(`Key not found : ${val}`));};}constpgLoader=async(client: Object,table: TableSinglePrimaryKey,ids: Array<string>,key?: string)=>{const_key=key||table.primaryKey;constwhere=ids.map(id=>`'${id}'`).join(' , ');constsql=`select ${Object.keys(table.fields).join(', ')} from ${table.tableName} where ${_key} in (${where})`;// console.log('pg loader sql: ', sql);// const TAG = `${table.tableName}-${Math.random()}`;// console.time(TAG);try{constresult=awaitclient.query(sql,[]);// console.timeEnd(TAG);const{ rows }=result;// order rows by idsreturnnormalizeResults(ids,_key,id=>id.toString())(rows);}catch(err){console.log('ERROR:POSTGRESQL:',err);returnnormalizeResults(ids,_key,id=>id.toString())([]);}};exportdefaultpgLoader;
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: