[SQL Generator] select

This commit is contained in:
jeffcheasey88 2023-11-20 14:42:47 +01:00
parent d7b367fcad
commit 5b6da187cc
2 changed files with 16 additions and 5 deletions

View file

@ -1,7 +1,10 @@
package dev.peerat.mapping.providers.mysql; package dev.peerat.mapping.providers.mysql;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.peerat.parser.java.Value;
import dev.peerat.parser.java.Value.LambdaValue;
import dev.peerat.parser.java.Value.MethodCallValue; import dev.peerat.parser.java.Value.MethodCallValue;
public class MySQLRequestBuilder{ public class MySQLRequestBuilder{
@ -20,8 +23,16 @@ public class MySQLRequestBuilder{
return "SELECT *"; return "SELECT *";
} }
if(method.equals("select()")){ if(method.equals("select()")){
throw new RuntimeException(value.getParameters().get(0)+""); LambdaValue include = (LambdaValue) value.getParameters().get(0);
// return "SELECT "; 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; return null;
@ -29,6 +40,7 @@ public class MySQLRequestBuilder{
public void build(){ public void build(){
this.select = toStringOperation(calls.get(0)); this.select = toStringOperation(calls.get(0));
throw new RuntimeException(this.select);
} }
} }

View file

@ -42,15 +42,14 @@ public class MySQLProvider implements Provider{
Value value = operation.getValue(); Value value = operation.getValue();
if(value instanceof MethodCallValue){ if(value instanceof MethodCallValue){
MethodCallValue call = (MethodCallValue)value; MethodCallValue call = (MethodCallValue)value;
throw new RuntimeException(clazz.getName().getValue()+" - "+call); List<MethodCallValue> list = new LinkedList<>();
/*List<MethodCallValue> list = new LinkedList<>();
while(call.base() instanceof MethodCallValue){ while(call.base() instanceof MethodCallValue){
list.add(0, call); list.add(0, call);
call = (MethodCallValue) call.base(); call = (MethodCallValue) call.base();
} }
list.add(0, call); list.add(0, call);
MySQLRequestBuilder builder = new MySQLRequestBuilder(list); MySQLRequestBuilder builder = new MySQLRequestBuilder(list);
builder.build();*/ builder.build();
} }
} }