Elixir/Phoenix with Oracle (database)?

Hi there, I know this might not be the post Im looking for, but looks like you have enough experience to answer this I believe. It is posible to work with Elixir/Phoenix with Oracle Database? I believe No its gonna be the answer… but Im new to answer that yet.

//@nubunto

2 Likes

What you are looking for is Oracle database adapter for Ecto, most likely. I do not believe you will find working one. The effort to develop one was started couple of times but looks abandoned.

You probably need to fall back to Erlang’s ODBC driver, that allows you to use native driver to be interfaced and connected to Oracle database. Something like this:

But please note, by doing so you will need to work with raw SQL queries, and not so nicely structured replies. You won’t be able to use Ecto’s changesets etc.

2 Likes

I was hoping to create a ServerSide Webpage using Phoenix and Oracle Database for my final Database project, I really want to impress my teacher with Phoenix but it looks like a bit hard to do, still Im gonna try the tutorial from that link you shared. Thanks for your time Huber, I love how fast someone answered my question.

3 Likes

You could also look at creating a custom Ecto adapter.

This blog post by @michalmuskala is a good place to start: http://michal.muskala.eu/2015/07/07/creating-ecto-adapters.html

Creating adapters for Ecto is really easy. The documentation is great (as in all core projects in Elixir), there are many helpful people, and the APIs you have to implement are straightforward and clear. It’s even easier if you want to create an adapter for a SQL database, as there is already a generic SQL adapter implementing a lot of common behaviour for you.

2 Likes

Thanks, this might be my start point.

2 Likes

Just to be clear here, @michalmuskala wrote that the task is easy in his blog post, but I believe he spent a few weeks implementing the adapter if you count in research, testing etc. If it’s your university assignment, and you are on a fairly short deadline, I would consider other options.

4 Likes

Yeah, I exaggerated a bit in that post. What is easy is the interface -
there’s only a couple functions that you need to implement. The harder part
is properly translating queries, although for an SQL database, I’d suspect
this to be much easier. You can most probably lean heavily on postgres and
mysql adapters.
Having said that, it’s a project on it’s own - probably too big to be just
a part of some other task.

2 Likes

Sorry @reinegado for the time it took for me to see this. The past few weeks have been a mess.

@michalmuskala and @hubertlepicki answered your question far better than I could. I’ve never used Phoenix with a database other than PostgreSQL and SQL Server.

But, in theory, you could use Phoenix without Ecto while integrating with the ODBC library from Erlang without implementing a Ecto adapter. But that may be counterproductive on the long run, since Ecto provides some niceties over raw SQL queries.

Drop me a line if you need help with anything. I’m still learning, but I love to help!

2 Likes

I forgot to mark as solved, sorry I was new to this forum.

It’s ok, you dont need to apologize. But Its interesting now that you mention, I mean, PostgreSQL and SQL Server aren’t the same as working with Oracle Database Express 11g? I just use SQL Developer, but I believe PostgreSQL it’s almost the same thing as SQL Developer since I just used once to do a practice, there are just few changes on how to do some queries and calls to default functions.

2 Likes

Yes, in essence these are all part of the SQL Standard. And yes, you can do some queries by changing it slightly. They have their differences between them, though.

For instance, in SQL Server, in order to get the auto generated ID of the item that was just inserted, you can do something like:

  INSERT INTO mytable (a, b, c) VALUES (1, 2, 3)
  SELECT SCOPE_IDENTITY() -- and this may fail in strange ways, so this is preferable in a stored procedure.

Or perhaps there’s a better way to do this in SQL Server, but you get the drift.

In PostgreSQL, this is far more simple:

INSERT INTO mytable(a, b, c) VALUES (1,2,3) RETURNING id;

So, both are SQL, but they have their differences and strengths at the same time.
The good thing about Ecto is that you don’t have to think about this, though :wink:

2 Likes

Well nice to read this stuff, I can’t wait to have a good knowledge and try Phoenix.

1 Like

Post is a month old but this is relevant for if anyone runs across this.

We were needing to setup a side-server that would give new functionality on a very old, very big, and very propriatery server that was built on oracle, however we did not want to touch the oracle server beyond what was needed.

Found out PostgreSQL’s extension mechanisms are wonderful, and there is an Oracle FDW extension for PostgreSQL (on PostgreSQL’s extension site) that also works wonderfully, so we store everything new in PostgreSQL and access the old Oracle tables through PostgreSQL, so we have a unified PostgreSQL view with both new tables and old Oracle tables. Depending on what you need to do then a direct BEAM Oracle driver may not be needed and you could use PostgreSQL to go through.

8 Likes

Hi, it’s Oracle Developer here :slight_smile: and Elixir rookie… old thread but for future check how Oracle DB can expose JSON through Oracle ORDS nowadays: http://www.oracle.com/technetwork/developer-tools/rest-data-services/overview/index.html
maybe this is the best way to go in the case there is no driver, but I actually don’t know yet how to handle REST endpoints in Elixir. Would it be possible to use Ecto for this too?

2 Likes

Huh, that sounds slow considering it would have to reconnect for every-single-request… o.O

You could do that in Elixir easily (HTTPoison or so), but there is no REST driver for Ecto as of yet. ^.^;

1 Like

Yep, so probably better for case when it is another data source, not main one, or in case when you have many sources under i.e. graphql api