erlangbureau / jamdb_oracle

Oracle Database driver for Erlang
MIT License
103 stars 46 forks source link

Error in 0.5.3 #137

Closed winks closed 1 year ago

winks commented 1 year ago

Hello, I moved to a new machine and I'm getting

'Expected Ecto.Adapters.Jamdb.Oracle to implement Ecto.Adapter.Storage in order to create storage for MyProject.FooRepo'

when building my phoenix app (so apparently the error had been there for a while but I didn't clean _build / deps in a while).

This is 0.5.3 on Elixir 1.14.4 on Erlang 24 and I tried several versions of ecto/ecto_sql 3.8.x and 3.9.x.

I am pretty sure this is related to #122 so I guess it's my fault anyway. If I revert the parts of that commit related to the Storage behaviour I get my app to build again but I'm fighting a different error here, so maybe I'll need to add some info later, but I wanted to report it first.

I've also not tried the current HEAD with ecto 3.10 but that's next on my agenda.

vstavskyi commented 1 year ago

Storage behaviour was removed because functions were not implemented

winks commented 1 year ago

Yes, and maybe I'm fundamentally misunderstanding the usage of the adapter behaviours here, but I have what I see as one of the most basic usages of the Oracle driver in Elixir. [1]

Maybe it's as easily solved as "just wrap Ecto.Adapters.Jamdb.Oracle and add the missing storage behaviour just to satisfy the compiler in your own module" but it feels wrong.

So yeah, I'm not saying it has to be there, but it seemed obvious, but I'm happy to solve this in another way, I just didn't find one yet. Maybe not using Ecto.Repo, but then I still wonder if it's a (deliberately) missing feature.

[1] Some shortened code example, I'm not even writing to the "storage" anymore, but I didn't change the code back from when the repo was read/write for me.

# usage

sql = "select * from table where id = #{FooRepo.var(1)}"
result = Ecto.Adapters.SQL.query(FooRepo, sql, [id])

# the module, supports Postgres for tests and Oracle for real data

defmodule MyProject.FooRepo do
    "oracle" ->
      use Ecto.Repo,
          otp_app: :bonsai,
          adapter: Ecto.Adapters.Jamdb.Oracle
      def nextval(sequence) do
        case Ecto.Adapters.SQL.query(MyProject.FooRepo, "SELECT #{sequence}.nextval from dual") do
          {:ok, %{columns: ["NEXTVAL"], num_rows: 1, rows: [[next_id]]}} -> next_id
        end
      end
      def var(x) do
        ":#{x}"
      end
    _ ->
      use Ecto.Repo,
          otp_app: :bonsai,
          adapter: Ecto.Adapters.Postgres
      def var(x) do
        "$#{x}"
      end
  end
done
winks commented 1 year ago

Ok, #elixir on Libera helped me out.

So what I was doing was:

mix ecto.setup
# which was an alias for
["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"]

what I should have done was:

ecto.create --repo MyProject.MyPostgresRepo ; ecto.migrate --repo MyProject.MyPostgresRepo

because I actually (currently) have no migrations here in the Oracle SQL code.

I'm gonna close this, sorrty for the noise.