lib/query-tree-builder.js
function buildQueryTree(
	dbDriver, recordTypes, propsTree, anchorNode, clauses, singleAxis) {

	// get and validate top records specification data
	const recordTypeDesc = recordTypes.getRecordTypeDesc(
		propsTree.desc.refTarget);
	const topIdPropName = recordTypeDesc.idPropertyName;
	const topIdColumn = recordTypeDesc.getPropertyDesc(topIdPropName).column;

	// create top query tree node
	const topNode = (
		anchorNode ?
			anchorNode.createChildNode(
				propsTree, recordTypeDesc.table, topIdColumn,
				false, false,
				topIdColumn, topIdColumn) :
			new QueryTreeNode(
				dbDriver, recordTypes, new Map(), new Map(), new Map(),
				singleAxis, propsTree, true, recordTypeDesc.table, 'z',
				topIdColumn)
	);
	topNode.rootPropNode = propsTree;

	// add top record id property to have it in front of the select list
	const idPropSql = topNode.tableAlias + '.' + topIdColumn;
	topNode.addSelect(makeSelector(idPropSql, topIdPropName));
	topNode.addPropSql(topIdPropName, idPropSql);
	topNode.addPropValueColumn(
		topIdPropName, topNode.table, topNode.tableAlias, topIdColumn);

	// add the rest of selected properties
	if (propsTree.hasChildren()) {
		const topMarkupCtx = {
			prefix: '',
			nextChildMarkupDisc: 'a'.charCodeAt(0)
		};
		for (let p of propsTree.children)
			if (!p.desc.isId()) // already included
				topNode.addProperty(p, clauses, topMarkupCtx);
	}

	// return the query tree
	return topNode;
}
function buildQueryTree(
	dbDriver, recordTypes, propsTree, anchorNode, clauses, singleAxis) {

	// get and validate top records specification data
	const recordTypeDesc = recordTypes.getRecordTypeDesc(
		propsTree.desc.refTarget);
	const topIdPropName = recordTypeDesc.idPropertyName;
	const topIdColumn = recordTypeDesc.getPropertyDesc(topIdPropName).column;

	// create top query tree node
	const topNode = (
		anchorNode ?
			anchorNode.createChildNode(
				propsTree, recordTypeDesc.table, topIdColumn,
				false, false,
				topIdColumn, topIdColumn) :
			new QueryTreeNode(
				dbDriver, recordTypes, new Map(), new Map(), new Map(),
				singleAxis, propsTree, true, recordTypeDesc.table, 'z',
				topIdColumn)
	);
	topNode.rootPropNode = propsTree;

	// add top record id property to have it in front of the select list
	const idPropSql = topNode.tableAlias + '.' + topIdColumn;
	topNode.addSelect(makeSelector(idPropSql, topIdPropName));
	topNode.addPropSql(topIdPropName, idPropSql);
	topNode.addPropValueColumn(
		topIdPropName, topNode.table, topNode.tableAlias, topIdColumn);

	// add the rest of selected properties
	if (propsTree.hasChildren()) {
		const topMarkupCtx = {
			prefix: '',
			nextChildMarkupDisc: 'a'.charCodeAt(0)
		};
		for (let p of propsTree.children)
			if (!p.desc.isId()) // already included
				topNode.addProperty(p, clauses, topMarkupCtx);
	}

	// return the query tree
	return topNode;
}
function buildQueryTree ( dbDriver , recordTypes , propsTree , anchorNode , clauses , singleAxis ) { // get and validate top records specification data const recordTypeDesc = recordTypes . getRecordTypeDesc ( propsTree . desc . refTarget ) ; const topIdPropName = recordTypeDesc . idPropertyName ; const topIdColumn = recordTypeDesc . getPropertyDesc ( topIdPropName ) . column ; // create top query tree node const topNode = ( anchorNode ? anchorNode . createChildNode ( propsTree , recordTypeDesc . table , topIdColumn , false , false , topIdColumn , topIdColumn ) : new QueryTreeNode ( dbDriver , recordTypes , new Map ( ) , new Map ( ) , new Map ( ) , singleAxis , propsTree , true , recordTypeDesc . table , 'z' , topIdColumn ) ) ; topNode . rootPropNode = propsTree ; // add top record id property to have it in front of the select list const idPropSql = topNode . tableAlias + '.' + topIdColumn ; topNode . addSelect ( makeSelector ( idPropSql , topIdPropName ) ) ; topNode . addPropSql ( topIdPropName , idPropSql ) ; topNode . addPropValueColumn ( topIdPropName , topNode . table , topNode . tableAlias , topIdColumn ) ; // add the rest of selected properties if ( propsTree . hasChildren ( ) ) { const topMarkupCtx = { prefix : '' , nextChildMarkupDisc : 'a' . charCodeAt ( 0 ) } ; for ( let p of propsTree . children ) if ( ! p . desc . isId ( ) ) // already included topNode . addProperty ( p , clauses , topMarkupCtx ) ; } // return the query tree return topNode ; }
Build query tree.

@private
@param {module:x2node-dbos.DBDriver} dbDriver The database driver.
@param {module:x2node-records~RecordTypesLibrary} recordTypes Record types
library.
@param {module:x2node-dbos~PropertyTreeNode} propsTree Selected properties
tree.
@param {module:x2node-dbos~QueryTreeNode} [anchorNode] Anchor table node,
if any.
@param {Array.<string>} clauses The clauses to include from the properties
tree.
@param {boolean} singleAxis <code>true</code> to enforce single axis query
tree.
@returns {module:x2node-dbos~QueryTreeNode} Top node of the query tree.
Build query tree .