function modify(query, res) {
	// jshint ignore:line

	/* If source is a primitive value then return it */
	if (
		typeof res === 'undefined' ||
		typeof res === 'number' ||
		typeof res === 'string' ||
		typeof res === 'boolean'
	) {
		return res;
	}

	var modifier = query.modifier || alasql.options.modifier;
	var columns = query.columns;
	if (typeof columns === 'undefined' || columns.length == 0) {
		// Try to create columns
		if (res.length > 0) {
			var allcol = {};
			for (var i = Math.min(res.length, alasql.options.columnlookup || 10) - 1; 0 <= i; i--) {
				for (var key in res[i]) {
					allcol[key] = true;
				}
			}

			columns = Object.keys(allcol).map(function (columnid) {
				return {columnid: columnid};
			});
		} else {
			// Cannot recognize columns
			columns = [];
		}
	}

	switch (modifier) {
		case 'VALUE':
			if (res.length === 0) return undefined;
			const keyValue = columns && columns.length > 0 ? columns[0].columnid : Object.keys(res[0])[0];
			return res[0][keyValue];

		case 'ROW':
			if (res.length === 0) return undefined;
			return Object.values(res[0]);

		case 'COLUMN':
			if (res.length === 0) return [];

			let key;
			if (columns && columns.length > 0) {
				key = columns[0].columnid;
			} else {
				key = Object.keys(res[0])[0];
			}

			let ar = [];
			for (var i = 0, ilen = res.length; i < ilen; i++) {
				ar.push(res[i][key]);
			}

			return ar;

		case 'MATRIX':
			if (res.length === 0) return undefined;
			return res.map(row => columns.map(col => row[col.columnid]));

		case 'INDEX':
			if (res.length === 0) return undefined;
			const keyIndex = columns && columns.length > 0 ? columns[0].columnid : Object.keys(res[0])[0];
			const valIndex = columns && columns.length > 1 ? columns[1].columnid : Object.keys(res[0])[1];
			return res.reduce((acc, row) => ({...acc, [row[keyIndex]]: row[valIndex]}), {});

		case 'RECORDSET':
			// Assuming alasql.Recordset is available in the scope
			return new alasql.Recordset({columns: columns, data: res});

		case 'TEXTSTRING':
			if (res.length === 0) return undefined;
			const keyTextString =
				columns && columns.length > 0 ? columns[0].columnid : Object.keys(res[0])[0];
			return res.map(row => row[keyTextString]).join('\n');
	}
	return res;
}
Modify res according modifier
 @function
 @param {object} query Query object
 @param res {object|number|string|boolean} res Data to be converted