Recursively parse a predicate calculus and build a SQL query
function(collectionName, criterion, key, parentKey) {
        var queryPart = '';


        if (parentKey) {
            return sql.prepareCriterion(collectionName, criterion, key, parentKey);
        }

        // OR
        if (key.toLowerCase() === 'or') {
            queryPart = sql.build(collectionName, criterion, sql.where, ' OR ');
            return ' ( ' + queryPart + ' ) ';
        }

        // AND
        else if (key.toLowerCase() === 'and') {
            queryPart = sql.build(collectionName, criterion, sql.where, ' AND ');
            return ' ( ' + queryPart + ' ) ';
        }

        // IN
        else if (_.isArray(criterion)) {
            queryPart = sql.prepareAttribute(collectionName, null, key) + " IN (" + sql.values(collectionName, criterion, key) + ")";
            return queryPart;
        }

        // LIKE
        else if (key.toLowerCase() === 'like') {
            return sql.build(collectionName, criterion, function(collectionName, value, attrName) {
                var attrStr = sql.prepareAttribute(collectionName, value, attrName);

                attrStr = attrStr.replace(/'/g, '"');

                // TODO: Handle regexp criterias
                if (_.isRegExp(value)) {
                    throw new Error('RegExp LIKE criterias not supported by the MySQLAdapter yet.  Please contribute @ http://github.com/balderdashy/sails-mysql');
                }

                var valueStr = sql.prepareValue(collectionName, value, attrName);

                // Handle escaped percent (%) signs [encoded as %%%]
                valueStr = valueStr.replace(/%%%/g, '\\%');
                var condition = (attrStr + " LIKE " + valueStr);

                //condition = condition.replace(/'/g, '"');

                return condition;
            }, ' AND ');
        }

        // NOT
        else if (key.toLowerCase() === 'not') {
            throw new Error('NOT not supported yet!');
        }

        // Basic criteria item
        else {
            return sql.prepareCriterion(collectionName, criterion, key);
        }

    }