我是Phoenix-Elixir的新手,我想在控制器中进行mysql查询。
mysql-query:从学生中选择*,其中first_name =" abc&#34 ;;
答案 0 :(得分:2)
假设您使用的是ecto和mariax,您可以使用Ecto.Query模块中提供的功能从任何地方进行查询。已在web.ex
中为您导入from/2宏。
def index(conn, params) do
query = from u in MyApp.User,
order_by: u.name
users = Repo.all(query)
end
对于更复杂的查询,您可能希望将查询(但不是Repo.all
中的double distance;
double lineHeight=-1;
double angleOff;
double angleCast;
for(int i=0;i<900;i++){
//i is the line across from the side.
angleOff=Math.atan(((i-450.0)/4000.0)/.1);
boolean hit=false;
board.setColor(GameFrame.m.getBackground());
board.drawLine(i, 922, i, 0);
for( double rayDist=0;!hit;rayDist+=.01){
try{
char block=Map.map[(int) (Map.p.x+Math.sin(angleOff+Map.p.angle)*rayDist)][(int) (Map.p.y-Math.cos(angleOff+Map.p.angle)*rayDist)];
if(block!='o'){
lineHeight=800/(rayDist*Math.abs(Math.cos(angleOff+Map.p.angle)));
switch(block){
case 'w':
board.setColor(Color.BLACK);
break;
case 'z':
board.setColor(Color.red);
break;
case 'g':
board.setColor(Color.green);
break;
case 'a':
board.setColor(Color.DARK_GRAY);
break;
}
hit=true;
}
}catch(Exception e){
hit=true;
lineHeight=800/(rayDist*Math.abs(Math.cos(angleOff+Map.p.angle)));
board.setColor(Color.black);
}
}
board.drawLine(i,(int) (461-(lineHeight/2)), i,(int) (461+(lineHeight/2)));
}
调用)移动到模型中。
答案 1 :(得分:0)
MyApp.Repo.all(
from s in MyApp.Students,
where: s.first_name == "Mary",
select s
)