Using a DAO to abstract our ORM from the rest of the application

We’re using MySQL with Sequelize.js as the ORM.

What we’re wondering is whether a DOA layer of abstraction is worthwhile. Here are our options:

  1. To use the Sequelize models throughout the application.

  2. To abstract Sequelize by building a layer that converts Sequelize
    models to Backbone models so that we’re using Backbone throughout
    the rest of the application instead.

Is abstraction important in this case or is it normal to use Models from the ORM throughout the other layers?

2

Don’t do it. An extra layer of hand-written code will cost you far more than you think, and return far less.

Building a DAO layer is worthwhile only if: Sequelize proves inadequate, and you can’t modify Sequelize to meet your requirements, and there is another ORM that can do what you need, and the cost of building the DAO layer is less than the cost of switching your code to a new ORM.

I expect that it will cost just as much, and probably more, to create and maintain the DAO layer than you would spend later changing ORMs.

3

Even though this is a really old question, I want to add another opinion regarding using daos or not.

First of all, of course it depends. It depends on your personal likings, your style, your teams style, the expected size of the applicatio you are building and much more non functional stuff.

And, of course, there are costs. Daos do cost a lot. You need to maintain a lot of code, and you need (at least you should) test it. So why do pay for this?

  • Actually, the need to test the code is no extra cost. You should have tested the same code if you wouldn’t have used the dao pattern. But with the dao pattern, it is easier to test because your unit of work just became a lot smaller. Your business code suddenly is indepentend of your query implementation. You can test both without the other by mocking the dao. How nice 🙂
  • Actually, your cost to maintain the code is also no extra cost. All the extra code is just a little bit of glue code to keep it all together. The net code remains the same. Even better, encouraging code reuse can save you net code. See next point.
  • If your querys are non trivial, they just became a lot easier to reuse if implemented in a dao. You do not even think about implementing it in place. Of course you are looking through your daos methods to check if you already implemented getAllMyStuffThatHappendSinceYesterdayExplicitlyWithoutSomeEagerlyLoadedAssociation.
  • Edit: Another great feature of using daos is you are independent of shortcomings of the generalization of sequelize. You know your query will always return an entity and never will be undefined? Wounderfull. Your signature just became a lot more expressive compared to sequelizes findOne(...):Promise<T|undefined>.

Also, in my personal opinion, it doesn’t matter if you implement your DAOs as first class citizens or just as “active records” within your Sequelize model classes. I perceive them as daos as well. But if you implement it as first class citizens, testing becomes way easier.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật