docs: function expression_query(parent, prop, type_name, type_prop, fields) {
  
  				fields = (fields || [{'query':'*'}]);
  
  				var map = {};
  
  				var query = "SELECT "+fields.map(function(f, i) {
  					var k;
  					if(f.key) {
  						k = 'p__' + i;
  						map[k] = f;
  						return f.query + ' AS ' + k;
  					} else {
  						return f.query;
  					}
  				}).join(', ')+" FROM documents WHERE type = $1 AND "+get_pg_prop(type_prop)+" = $2";
  
  				var rows = plv8.execute(query, [type_name, parent.id]);
  
  				if(!is_array(rows)) {
  					return rows;
  				}
  
  				var errors = [];
  
  				rows = rows.map(function(obj) {
  					Object.keys(obj).forEach(function(key) {
  						if(!map.hasOwnProperty(key)) {
  							return;
  						}
  						var spec = map[key];
  						if(!is_object(spec)) {
  							errors.push( error('mapped resource missing') );
  							return;
  						}
  						if(!is_string(spec.key)) {
  							errors.push( error('key missing') );
  							return;
  						}
  						var value = obj[key];
  						delete obj[key];
  
  						if(is_string(spec.datakey)) {
  							if(!obj[spec.datakey]) {
  								obj[spec.datakey] = {};
  							}
  							obj[spec.datakey][spec.key] = value;
  						} else {
  							obj[spec.key] = value;
  						}
  					});
  					return obj;
  				});
  
  				if(errors.length >= 1) {
  					return errors.shift();
  				}
  
  				return rows;
  			}