ma.vi.esql.function.Lower Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esql Show documentation
Show all versions of esql Show documentation
ESQL, SQL enhanced with metadata compiling to various relational databases
/*
* Copyright (c) 2020 Vikash Madhow
*/
package ma.vi.esql.function;
import ma.vi.esql.parser.Translatable;
import ma.vi.esql.parser.expression.Expression;
import ma.vi.esql.parser.expression.FunctionCall;
import ma.vi.esql.type.Types;
import java.util.List;
import static java.util.Collections.singletonList;
import static ma.vi.esql.parser.Translatable.Target.JAVASCRIPT;
/**
* Function to convert text to lower case.
*
* @author Vikash Madhow ([email protected])
*/
public class Lower extends Function {
public Lower() {
super("lower", Types.StringType,
singletonList(new FunctionParameter("text", Types.StringType)));
}
@Override
public String translate(FunctionCall call, Translatable.Target target) {
List> args = call.arguments();
if (target == JAVASCRIPT) {
return '(' + args.get(0).translate(target) + ").toLowerCase()";
} else {
// ESQL and all databases
return name + '(' + args.get(0).translate(target) + ')';
}
}
}