vendredi 24 février 2017

Flask SQLAlchemy Data Mapper vs Active Record Pattern

I have recently started working on Flask and Flask-SQLAlchemy. Coming from Django background I found Flask-SQLAlchmey to be quite complex. I have read that SQLAlchemy implements Data Mapper pattern while Django ORM is based on Active Record Pattern.

Here is a sample code written that implements repository pattern to access the database.

Here is another link of a comment by S.Lott(271k) reputation who says that ORM is the data access layer and it is seperate from model.

My questions are these?

  1. Can you provide a practical use case in the above example or an example of your own where Data mapper pattern is useful? Everywhere I have read is that data mapper pattern is useful in complex situation, but not seen examples
  2. Is using repositories pattern as in above case same as using a data mapper pattern?
  3. Does data mapper advocates write select queries in a different class than the model as done in the example
  4. Why is Question.query.filter_by(text = text).all() not better to use than db.session.query(Question).filter(Question.text == text).all()

It is not a duplicate of DataMapper vs ActiveRecord pattern because this just tells the definition, I am more interested in the practical examples

Aucun commentaire:

Enregistrer un commentaire