src/nopg.js
function _get_result(Type) {
	return function(rows) {
		if(!rows) { throw new TypeError("failed to parse result"); }
		var doc = rows.shift();
		if(!doc) { return; }

		if(doc instanceof Type) {
			return doc;
		}

		var obj = {};
		ARRAY(Object.keys(doc)).forEach(function(key) {

			if(key === 'documents') {
				obj['$'+key] = {};
				ARRAY(Object.keys(doc[key])).forEach(function(k) {
					if(is.uuid(k)) {
						obj['$'+key][k] = _get_result(NoPg.Document)([doc[key][k]]);
					} else {
						obj['$'+key][k] = doc[key][k];
					}
				});
				return;
			}

			obj['$'+key] = doc[key];
		});

		_parse_object_expressions(obj);

		return new Type(obj);
	};
}
function _get_result(Type) {
	return function(rows) {
		if(!rows) { throw new TypeError("failed to parse result"); }
		var doc = rows.shift();
		if(!doc) { return; }

		if(doc instanceof Type) {
			return doc;
		}

		var obj = {};
		ARRAY(Object.keys(doc)).forEach(function(key) {

			if(key === 'documents') {
				obj['$'+key] = {};
				ARRAY(Object.keys(doc[key])).forEach(function(k) {
					if(is.uuid(k)) {
						obj['$'+key][k] = _get_result(NoPg.Document)([doc[key][k]]);
					} else {
						obj['$'+key][k] = doc[key][k];
					}
				});
				return;
			}

			obj['$'+key] = doc[key];
		});

		_parse_object_expressions(obj);

		return new Type(obj);
	};
}
function _get_result ( Type ) { return function ( rows ) { if ( ! rows ) { throw new TypeError ( "failed to parse result" ) ; } var doc = rows . shift ( ) ; if ( ! doc ) { return ; } if ( doc instanceof Type ) { return doc ; } var obj = { } ; ARRAY ( Object . keys ( doc ) ) . forEach ( function ( key ) { if ( key === 'documents' ) { obj [ '$' + key ] = { } ; ARRAY ( Object . keys ( doc [ key ] ) ) . forEach ( function ( k ) { if ( is . uuid ( k ) ) { obj [ '$' + key ] [ k ] = _get_result ( NoPg . Document ) ( [ doc [ key ] [ k ] ] ) ; } else { obj [ '$' + key ] [ k ] = doc [ key ] [ k ] ; } } ) ; return ; } obj [ '$' + key ] = doc [ key ] ; } ) ; _parse_object_expressions ( obj ) ; return new Type ( obj ) ; } ; }
Take first result from the database query and returns new instance of `Type`
Take first result from the database query and returns new instance of Type