我是菲尼克斯/灵丹妙药的新手,需要帮助。
我尝试将ecto.query的结果放在变量中,如下所示
owner =
(from ex in "executors",
where: ex.email == ^account_name,
where: ex.pass_hash == ^pwd,
select: ex.id )
|> Repo.all()我需要'owner‘是一个像ex.id一样的整数,但它就像一个字符- '\a','M’等。
如何正确地从整数类型的查询中获取结果,或者如何将其从代码点转换为整数?
提前感谢
发布于 2017-08-12 00:04:35
TL;DR
[owner | _] =
(from ex in "executors",
where: ex.email == ^account_name,
where: ex.pass_hash == ^pwd,
select: ex.id )
|> Repo.all()说明:
Repo.all()返回整数的列表,而不是单个整数。当你检查它的时候,它会被解释为一个列表。如果您是肯定的,则只有一个结果,执行上面的匹配,甚至:
[owner] = ...或者,更好的是:
owner = (<QUERY>)
|> Repo.one()https://stackoverflow.com/questions/45636430
复制相似问题