在下面的链接中做了一些研究之后
https://github.com/elixir-lang/ecto/tree/master/examples/simple
我对如何在长生不老药中使用 ecto 有点困惑。
总是有一个声明如下的模式
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
然后在“查询”部分
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 使用 Weather中声明的模式形成查询
我的问题是我只想连接到现有数据库“TESTDB”并进行一些 SELECT,我不需要任何新的 schmema 来完成我的工作。请问可以在ecto中做吗?
当我创建自己的查询时
query = from w in tenant
在我输入命令后$ mix do deps.get, compile
错误告诉我function tenant/0 undefined
tenant
不是函数,它只是一个TESTDB
我没有在任何地方声明的表
我想我只是在ecto中迷失了自己