Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sql += ' UNION ' + _buildQuery(opts.union);
}
if (opts.unionAll) {
sql += ' UNION ALL ' + _buildQuery(opts.unionAll);
}
if (opts.intersect) {
sql += ' INTERSECT ' + _buildQuery(opts.intersect);
}
if (opts.except) {
sql += ' EXCEPT ' + _buildQuery(opts.EXCEPT);
}
// group by, order by and limit should be in the end of the statement
if (opts.groupBy) {
var group;
if (_.isArray(opts.groupBy)) {
group = opts.groupBy.join(', ');
} else {
group = opts.groupBy;
}
sql += ' GROUP BY ' + group;
}
if (opts.orderBy) {
var order;
if (_.isArray(opts.orderBy)) {
order = opts.orderBy.join(', ');
} else {
order = opts.orderBy;
}
sql += ' ORDER BY ' + order;
where = [];
where = whereBuilder(where, opts.where);
where = where.join(' AND ');
} else {
where = opts.where;
}
sql += ' WHERE ' + where;
} else {
sql += ' WHERE 1=1';
}
// WHERE NOT
if (opts.wherenot && !_.isEmpty(opts.wherenot)) {
var wherenot;
if (_.isArray(opts.wherenot)) {
wherenot = opts.wherenot.join(' AND ');
} else if ( typeof opts.wherenot === 'object') {
wherenot = [];
// use the where not operator
wherenot = whereBuilder(wherenot, opts.wherenot, " != ");
wherenot = wherenot.join(' AND ');
} else {
wherenot = opts.wherenot;
}
sql += ' AND ' + wherenot;
}
// LIKE
if (opts.like) {
var like;
}
// group by, order by and limit should be in the end of the statement
if (opts.groupBy) {
var group;
if (_.isArray(opts.groupBy)) {
group = opts.groupBy.join(', ');
} else {
group = opts.groupBy;
}
sql += ' GROUP BY ' + group;
}
if (opts.orderBy) {
var order;
if (_.isArray(opts.orderBy)) {
order = opts.orderBy.join(', ');
} else {
order = opts.orderBy;
}
sql += ' ORDER BY ' + order;
}
if (opts.limit) {
sql += ' LIMIT ' + opts.limit;
if (opts.offset) {
sql += ' OFFSET ' + opts.offset;
}
}
return sql;
}
where = [];
where = whereBuilder(where, opts.where);
where = where.join(' AND ');
} else {
where = opts.where;
}
sql += ' WHERE ' + where;
} else {
sql += ' WHERE 1=1';
}
// WHERE NOT
if (opts.wherenot && !_.isEmpty(opts.wherenot)) {
var wherenot;
if (_.isArray(opts.wherenot)) {
wherenot = opts.wherenot.join(' AND ');
} else if ( typeof opts.wherenot === 'object') {
wherenot = [];
// use the where not operator
wherenot = whereBuilder(wherenot, opts.wherenot, " != ");
wherenot = wherenot.join(' AND ');
} else {
wherenot = opts.wherenot;
}
sql += ' AND ' + wherenot;
}
// LIKE
if (opts.like) {
var like;
}
// group by, order by and limit should be in the end of the statement
if (opts.groupBy) {
var group;
if (_.isArray(opts.groupBy)) {
group = opts.groupBy.join(', ');
} else {
group = opts.groupBy;
}
sql += ' GROUP BY ' + group;
}
if (opts.orderBy) {
var order;
if (_.isArray(opts.orderBy)) {
order = opts.orderBy.join(', ');
} else {
order = opts.orderBy;
}
sql += ' ORDER BY ' + order;
}
if (opts.limit) {
sql += ' LIMIT ' + opts.limit;
if (opts.offset) {
sql += ' OFFSET ' + opts.offset;
}
}
return sql;
}
exports.createStyle = function(controller, opts, defaults) {
var classes, apiName;
if (!opts) return {};
classes = _.isArray(opts.classes) ? opts.classes.slice(0) : _.isString(opts.classes) ? opts.classes.split(/\s+/) : [];
apiName = opts.apiName;
apiName && -1 === apiName.indexOf(".") && (apiName = addNamespace(apiName));
var styleArray;
styleArray = controller && _.isObject(controller) ? require("alloy/widgets/" + controller.widgetId + "/styles/" + controller.name) : require("alloy/styles/" + controller);
var styleFinal = {};
var i, len;
for (i = 0, len = styleArray.length; len > i; i++) {
var style = styleArray[i];
var styleApi = style.key;
style.isApi && -1 === styleApi.indexOf(".") && (styleApi = (CONST.IMPLICIT_NAMESPACES[styleApi] || CONST.NAMESPACE_DEFAULT) + "." + styleApi);
if (style.isId && opts.id && style.key === opts.id || style.isClass && _.contains(classes, style.key)) ; else {
if (!style.isApi) continue;
-1 === style.key.indexOf(".") && (style.key = addNamespace(style.key));
if (style.key !== apiName) continue;
}
if (style.queries && style.queries.formFactor && !Alloy[style.queries.formFactor]) continue;
target = arguments[1] || {};
i = 2;
}
"object" == typeof target || _.isFunction(target) || (target = {});
for (;length > i; i++) {
options = arguments[i];
if (null != options) {
"string" == typeof options && (options = options.split(""));
for (name in options) {
src = target[name];
copy = options[name];
if (target === copy) continue;
if (deep && copy && _.isObject(copy) && ((copy_is_array = _.isArray(copy)) || !_.has(copy, "apiName"))) {
if (copy_is_array) {
copy_is_array = false;
clone = src && _.isArray(src) ? src : [];
} else clone = _.isDate(copy) ? new Date(copy.valueOf()) : src && _.isObject(src) ? src : {};
target[name] = deepExtend(deep, clone, copy);
}
target[name] = copy;
}
}
}
return target;
}
_.each(data, function(v, f) {
if (_.isArray(v)) {//select multiple items
var innerWhere = [];
_.each(v, function(value) {
innerWhere.push(f + whereOperator + _valueType(value));
});
where.push(innerWhere.join(' OR '));
} else if (_.isObject(v)) {
where = whereBuilder(where, v, whereOperator);
} else {
where.push(f + whereOperator + _valueType(v));
}
});
return where;