What is the difference between an ORM and an ODM?

Deadly 提交于 2019-12-29 10:04:11

问题


I am trying to figure out what the difference is between ORM and ODM, as far as I understand the concept, ORM (Object Relational Mapper) maps the relations between data, where as ODM (Object Document Mapper) deals with documents. Am I right in assuming that mySQL is an example of ORM and MongoDB is a example of ODM?

As I am sure you can see, I am not too familiar with the theory of the concept. Could someone please clarify the differences between the two?


回答1:


MySQL is an example of a relational database - you would use an ORM to translate between your objects in code and the relational representation of the data.

Examples of ORMs are nHibernate, Entity Framework, Dapper and more...

MongoDB is an example of a document database - you would use an ODM to translate between your objects in code and the document representation of the data (if needed).

Mandango is an example of an ODM for MongoDB.




回答2:


An ORM maps between an Object Model and a Relational Database. An ODM maps between an Object Model and a Document Database. MySQL is not an ORM, it's a Relational Database, more specifically, a SQL Database. MongoDB is not an ODM, it's a Document Database.




回答3:


Essencially, an ORM use a SQL database Driver like ODBC, JDBC or OLEDB to translate the object notation to relational notation and an ODM use a JSON or JSONB api to translate the Object notation to Document notation.

There are different kind of implementations under the hood.

PS: JSONB is a JSON text document notation stored in a binary format as used by MongoDB.




回答4:


Mongoose is a good example for ODM(Object Data Model) for MongoDB in which you can directly perform operations with objects and that gets translated into the appropriate query and schema. It can be found Here at https://mongoosejs.com/




回答5:


When you first learn how to work with database, it all comes down to two types of database set ups which are ORM (object Relation Mapping) and ODM (Object Document Mapping)

ORM which is to map an object with a relational world, it basically converts data between incompatible types in object oriented programming languages. ORM wraps the implementation specific details of storage drivers in an API (application program interface), and maps the relational fields to an object members. For example if I have a table of employees, it is mapped to a single object for all employees, with various methods associated with it.

ODM on the other hand is an Object Document Mapper, which maps objects with a Document Database like MongoDB.

The main difference is that ORM is for MySQL databases, while ODM does the mapping for document representation of data. best way to remember what ORM does would be to think of it as an excel spread sheet, with rows and columns. When using this set up, you want to be sure you have a great plan on how you want to tackle the current application, it does not allow as many modifications like ODM does. With ODM we can add new fields and properties easily but with ORM when adding a new field you need to keep in mind that nothing stays empty so it needs a value to be as default unless you want to go into each and modify.



来源:https://stackoverflow.com/questions/12261866/what-is-the-difference-between-an-orm-and-an-odm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!