46 lines
1.2 KiB
Java
46 lines
1.2 KiB
Java
package dev.peerat.mapping.providers.mysql;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import dev.peerat.parser.java.Value;
|
|
import dev.peerat.parser.java.Value.LambdaValue;
|
|
import dev.peerat.parser.java.Value.MethodCallValue;
|
|
|
|
public class MySQLRequestBuilder{
|
|
|
|
private List<MethodCallValue> calls;
|
|
private String select;
|
|
private String from;
|
|
|
|
public MySQLRequestBuilder(List<MethodCallValue> calls){
|
|
this.calls = calls;
|
|
}
|
|
|
|
private String toStringOperation(MethodCallValue value){
|
|
String method = value.getToken().getValue();
|
|
if(method.equals("selectAll()")){
|
|
return "SELECT *";
|
|
}
|
|
if(method.equals("select()")){
|
|
LambdaValue include = (LambdaValue) value.getParameters().get(0);
|
|
MethodCallValue keep = (MethodCallValue)include.getOperations().get(0);
|
|
List<String> binds = new ArrayList<>();
|
|
for(Value param : keep.getParameters()){
|
|
binds.add(param.getToken().getValue());
|
|
}
|
|
String result = ""; //optimise with iterator
|
|
for(String bind : binds) result+=","+bind;
|
|
result=result.substring(1);
|
|
return "SELECT "+result;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void build(){
|
|
this.select = toStringOperation(calls.get(0));
|
|
throw new RuntimeException(this.select);
|
|
}
|
|
|
|
}
|