LoginSignup
3
0

More than 3 years have passed since last update.

Ectoで生SQLを実行して結果を構造体で受け取る

Last updated at Posted at 2020-09-12
    result =
      """
      SELECT * FROM user
      """
      |> Repo.query!()

   users =
      Enum.map(result.rows, &Repo.load(User, {result.columns, &1}))

Ecto.Repo.load/2 を使うことで任意の構造体に入れることが可能

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0