我在 Elixir 中有一个非常简单的应用程序,它使用 Ecto 在 Postgres 上的表中运行 SELECT 查询。\n表名称是“person”,有 2 列:“name”和“age”。
\n这是应用程序:
\n/ecto_app\n |-application.ex\n |-repo.ex\n
Run Code Online (Sandbox Code Playgroud)\n应用程序.ex:
\ndefmodule EctoApp.Application do\n\n use Application\n\n require Logger\n\n @impl true\n def start(_type, _args) do\n children = [\n EctoApp.Repo\n ]\n\n opts = [strategy: :one_for_one, name: EctoApp.Supervisor]\n Logger.debug("Starting Ecto App")\n Supervisor.start_link(children, opts)\n end\nend\n
Run Code Online (Sandbox Code Playgroud)\n回购协议:
\ndefmodule EctoApp.Repo do\n use Ecto.Repo,\n otp_app: :ecto_app,\n adapter: Ecto.Adapters.Postgres\n\n import Ecto.Query\n\n require Logger\n\n\n def get_people() do\n query = from p in "person",\n select: [p.name, p.age]\n result= EctoApp.Repo.all(query)\n …
Run Code Online (Sandbox Code Playgroud)