DEV Community

Discussion on: ORM vs. SQL?

Collapse
 
bertilmuth profile image
Bertil Muth

Interesting. Does that mean you manually need to implement a Mapper for every entity?

Collapse
 
dmfay profile image
Dian Fay • Edited

It can, but that's kind of doing it the hard way. iBatis/MyBatis, for example, used to require a lot of configuration -- you'd write your own XML mapping which translates columns in each query result to their corresponding class fields, and write SQL which inserts, updates, or deletes records in tables based on object properties (I am given to understand they've automated most of the basic one-table-at-a-time CRUD since I last used it). What's interesting about doing this is that you're not restricted to a one-to-one table:class mapping: you can source a domain object from a complex view, and decompose it into its constituent tables when you persist. It's immensely powerful and lets you do some really elegant things with your schema design.

Massive's secret sauce is full introspection: it builds an API that lets you work with tables, views, and functions as if you were querying them directly, just using JavaScript instead of SQL. You don't need any domain classes or models at all.

Thread Thread
 
feroxneto profile image
Fernando Ferox Neto

Hi @Dian,

It sounds quite interesting, do you have further resources that one can look into to learn more on this.

Thread Thread
 
dmfay profile image
Dian Fay

Fowler has a book about enterprise patterns in general including the data mapper, although I have to admit I haven't read it. Other than that, your best bet is probably to learn by doing. Massive has an interactive REPL and extensive documentation if you do Node, or you could look at some of the other implementations from the Wikipedia article.

Thread Thread
 
feroxneto profile image
Fernando Ferox Neto

Thanks for the pointes Dian, I really appreciate it.