fix simpleMap(rows) for find/getAll
This commit is contained in:
		
							parent
							
								
									5119cb1bf0
								
							
						
					
					
						commit
						69e5f9eda8
					
				@ -56,21 +56,11 @@ function wrap(db, dir) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function simpleParse(row) {
 | 
			
		||||
      var obj;
 | 
			
		||||
 | 
			
		||||
      if (!row) {
 | 
			
		||||
        return null;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (row.json) {
 | 
			
		||||
        obj = JSON.parse(row.json);
 | 
			
		||||
      } else {
 | 
			
		||||
        obj = {};
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      obj[idnameCased] = row[idname];
 | 
			
		||||
 | 
			
		||||
      return obj;
 | 
			
		||||
      return simpleMap([row])[0] || null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function simpleMap(rows) {
 | 
			
		||||
@ -86,11 +76,20 @@ function wrap(db, dir) {
 | 
			
		||||
 | 
			
		||||
        if (row.json) {
 | 
			
		||||
          obj = JSON.parse(row.json);
 | 
			
		||||
          delete row.json;
 | 
			
		||||
        } else {
 | 
			
		||||
          obj = {};
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        obj[idnameCased] = row[idname];
 | 
			
		||||
        delete row[idname];
 | 
			
		||||
 | 
			
		||||
        Object.keys(row).forEach(function (fieldname) {
 | 
			
		||||
          // TODO warn if overriding proper field? (shouldn't be possible)
 | 
			
		||||
          obj[camelCase(fieldname)] = row[fieldname];
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        return obj;
 | 
			
		||||
      });
 | 
			
		||||
      // set up for garbage collection
 | 
			
		||||
      rows.length = 0;
 | 
			
		||||
@ -129,7 +128,6 @@ function wrap(db, dir) {
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      console.log('sql', sql);
 | 
			
		||||
      return db.allAsync(sql, []).then(simpleMap);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user