在下面的链接中进行了一些研究之后
After doing some research in the link below
github/elixir-lang/ecto/tree/master/examples/simple
I
这里有总是声明为
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 endecto gona使用在Weather中声明的模式
ecto gona form a query using the schema declared in Weather
构成查询我的问题是我只想连接到现有数据库'TESTDB'并执行一些SELECT,我不需要任何新的模式即可完成工作。
My question is that I just want to connect to an existing database 'TESTDB' and doing some SELECT, I don't need any new schmema to do my work. Is it possible to do it in ecto please?
当我创建自己的查询时,例如
When I create my own query like
query = from w in tenantc> $ mix do deps.get,编译
after I input the command $ mix do deps.get, compile
该错误告诉我函数租户/ 0未定义
承租人不起作用,它只是 TESTDB ,我没有任何位置声明
tenant is not function, it just a table in TESTDB that I didn't declare anywhere
我想我只是失去了自己在外生
I think I just lost myself in ecto
推荐答案无论是否使用 Ecto 创建表,都需要声明表的模式。我认为目前没有自动执行此操作的选项。因此,例如,您可以使用以下命令:
You need to declare the schema for your table whether you create it using Ecto or not. I don't think there's currently an option to do this automatically. So for example you can have something like:
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然后在租户中从w执行 query =,选择:w
And then do query = from w in Tenant, select: w
更多推荐
Elixir ecto连接到现有数据库
发布评论