All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ma.vi.esql.function.Lower Maven / Gradle / Ivy

Go to download

ESQL, SQL enhanced with metadata compiling to various relational databases

There is a newer version: 0.5.1
Show newest version
/*
 * 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) + ')';
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy