Elixir ecto connects to an existing database

After some research in the link below

https://github.com/elixir-lang/ecto/tree/master/examples/simple

I am a little confused about how to use ecto in an elixir.

There is always a circuit declared as

defmodule Weather do
  use Ecto.Model

  schema "weather" do
    field :city, :string
    field :temp_lo, :integer
    field :temp_hi, :integer
    field :prcp, :float, default: 0.0
    timestamps
  end
end

and then in the "Request" part

 def sample_query do
   query = from w in Weather,
      where: w.prcp > 0.0 or is_nil(w.prcp),
      select: w
   Simple.Repo.all(query)
   end
 end

ecto gona makes a request using the scheme declared in Weather

My question is that I just want to connect to an existing TESTDB database and do some SELECT, I don't need a new schmema to do my job . Can this be done in ecto, please?

When I create my own request, for example

query = from w in tenant

after entering the command $ mix do deps.get, compile

the error tells me function tenant/0 undefined

tenant , TESTDB,

, ecto

+4
2

, Ecto . , . , - :

defmodule Tenant do
  use Ecto.Model

  schema "tenant" do
    field :id, :integer
    field :name, :string
    # and so on depending on the columns in your table
  end
end

query = from w in Tenant, select: w

+5

, :

from p in "posts", where: p.id > 0

- , . , SQL-:

Ecto.Adapters.SQL.query(YourRepo, "SELECT $1", [1])

, Ecto.

+8

All Articles