Woody88

Woody88

Is ORM the only way or the right way to design and deal with data?

Hi guys so I have been trying to build is small library app - the app just will ultimately allow users to reserve study rooms or auditoriums. It will also allow users to book and expert(just a person that has a certain skill they need, like math…) to help them with whatever needs they have. The app reads a CSV file that has all the library branches from the city and it also contains all the rooms that each branch have.

Ok, now the real issue. Due to the new suggest way of building things in Phoenix 1.3 (context) I have been trying to build my little elixir app following the context rule. I originally decided to use processes to hold my states such User, Branch, Room, Availability, and Reservation. But, It felt like I was starting to rewriting ORM crud operations. Thus, I decided to find something that did not require me to use Ecto because I was getting really confused on where to put schema, models and so on. I found this repo Moebius, as I’m using it I found my defining functions such as from_model, to_model basically mapping DB to my structs. Why? Well, this is what I have always learned from java, .net, Ruby and jumping to Phoenix.

I would like to know, can I just create my app without relying on structs to define my data and just use… I guess modules to define how to transform my data or what type of operation can be done with the retrieve DB data?

Pretty what is the right way? Or what the advantages and disadvantages between ORM and Directly just querying to you DB without transforming your data to a model?(Ecto vs Moebius?)

Whats is the correct or approved way of designing when it comes to this subject?

If feel like I am lacking some basic knowledge here, can anyone help?

Thank you.

Most Liked

michalmuskala

michalmuskala

Another important advantage of Ecto as a tool is that, as far as I know, it’s currently not possible to introduce, even by accident, an SQL injection vector using the query DSL - this is checked at compile-time.

OvermindDL1

OvermindDL1

The main advantage I see to using an ORM over raw calls is static ‘typing’ (at least making sure the names are correct) as I have a habit of mis-typing something and I like the compiler to catch me instead of getting a wtf SQL error later. ^.^

hubertlepicki

hubertlepicki

No, it’s not. Postgrex is pretty good on it’s own and not difficult to use. You can extend it’s functionality with type casting etc. to the level that can be very much all you need.
Check out: https://github.com/elixir-ecto/postgrex/tree/master/lib

But I’m not advocating you do that, esp. if you just start with Elixir.

peerreynders

peerreynders

In the other topic I mentioned the repository - it’s essentially a Façade which wraps your persistent storage access technology - whether it’s something as low-level as ODBC or high level as a relational mapper like Ecto. The only thing the context contributes is the boundary for the functionality of that (context’s) repository (which is necessary to support the capabilities of the context).

The more significant issue in terms of coupling are the data types (shape of data; structs) which are used to interface with the repository - for example if the repository returns and accepts types that are generated with the assistance of Ecto.Schema for use with Ecto.ChangeSet then the repository has failed to decouple the application from Ecto. On the flip-side a lot of the value that Ecto can provide is lost if the application is successfully decoupled - you’d essentially have to implement your own Unit of Work.

Another perspective is to simply, deliberately accept the coupling between, for example, Ecto and the rest of the context’s capabilities - provided that the context is small enough to be easily replaced in it’s entirety when the persistent storage technology changes sometime in the future.

hubertlepicki

hubertlepicki

I think in most cases, it’s going to be considerably more work.

Where Next?

Popular in Questions Top

ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement