Elixir - 阅读postgres结果

时间:2017-06-08 11:27:48

标签: elixir phoenix-framework elixir-framework

我需要读取原始的Postgres输出并迭代行值。

ww = %Postgrex.Result{columns: ["id", "tracking_link"], command: :select,
 connection_id: 22311, num_rows: 14,
 rows: [[2, "http://StarChef.com?id=1"],
  [3, "http://CaptainAmerica:TWSLiveWP.com?id=2"]]} 

ww [:rows] - 不提供输出

1 个答案:

答案 0 :(得分:0)

您需要使用.来访问结构的字段。括号语法仅适用于不是实现Access行为的结构或结构的映射。

iex(1)> ww = %Postgrex.Result{columns: ["id", "tracking_link"], command: :select,
...(1)>  connection_id: 22311, num_rows: 14,
...(1)>  rows: [[2, "http://StarChef.com?id=1"],
...(1)>   [3, "http://CaptainAmerica:TWSLiveWP.com?id=2"]]}
%Postgrex.Result{columns: ["id", "tracking_link"], command: :select,
 connection_id: 22311, num_rows: 14,
 rows: [[2, "http://StarChef.com?id=1"],
  [3, "http://CaptainAmerica:TWSLiveWP.com?id=2"]]}
iex(2)> ww.rows
[[2, "http://StarChef.com?id=1"],
 [3, "http://CaptainAmerica:TWSLiveWP.com?id=2"]]