Javascript node.js ORM that follows data-mapper pattern
Asked Answered
K

3

13

I've been working with active record and data mapper implementations of ORM enough to know the problems with using active record implemented ORM in my large projects. Right now I'm thinking to migrate one of my projects to node.js and trying to find the similar tools Im using right now. After research I didn't found any node.js ORM that follows data mapper pattern. They all are active record. Maybe I missing something, and you can tell me is there is a good popular ORM for node.js that doesn't follow active record pattern?

The libraries Ive looked on:

Koger answered 11/4, 2015 at 11:14 Comment(2)
Try StrongLoop, you can map types to tables and generate a REST client to be used with the REST API generated by the mappings. Dont know if this is what you are looking for but doesnt hurt putting it out there as a comment? :)Tartarean
@Tartarean it doesnt look like ormKoger
K
29

After lot of frustration of currently exist ORMs for JavaScript I have written my own ORM that supports TypeScript / ES6 / ES5 and follows data mapper patterns and all other best practices - TypeORM

Koger answered 16/10, 2016 at 6:21 Comment(1)
Thanks @Koger for the amazing TypeORM librarySortilege
P
3

I wrote an ORM for Node.js called node-data-mapper; it's available here: https://www.npmjs.com/package/node-data-mapper. It's an ORM for Node.js that uses the data-mapper pattern. The developer uses plain old JavaScript objects when reading from and writing to the database. Relationships between tables are not rigidly defined, which makes joining very flexible--in my opinion, anyway--albeit somewhat verbose. The actual data mapping algorithm is fast and short, and the complexity is linear (the transformation from tabular DB data to a normalized JavaScript object is done in one loop).

I also did my best to make it fairly fault tolerant. There's 100% code coverage and, while I know that doesn't prove the absence of defects, I did try to test as thoroughly as possible.

I modeled the interface very loosely after Doctrine 1. (I've used LINQ, Doctrine 1 and 2, and Hibernate fairly extensively, and of those ORMs I like the interface for Doctrine 1 the best. node-data-mapper is not a JavaScript port of Doctrine by any means, though, and the interface is significantly different.) The query interface returns promises using the deferred module.

I modeled the conditions (e.g. WHERE and ON clauses) after MongoDB's conditions. Hopefully that makes the conditions somewhat intuitive while providing a way for making reusable queries (specifically, complex SELECT queries that can be filtered securely in many different ways). The conditions are treated as a domain-specific language, and are lexed, parsed, and compiled.

Anyway, the module is something that I use in my personal projects, but I'd love to get some feedback from other developers in the community! I tried to provide plenty of examples to get people up and running quickly. Currently the module supports MySQL only, but I'm working on adding support for MSSQL.

Pili answered 28/5, 2016 at 6:36 Comment(0)
B
-8

The distinction between data-mapper pattern and active record doesn't really make sense in the dynamic language such as JavaScript. Typically data mapper is more lightweight in typed language, but in JS it does not really make a difference. From the top of my head, I can mention two very popular projects which you probably don't know:

Waterline.js is a Sails abstraction, which works quite well on top of many database systems.

If you would consider MongoDB for your DB - Mongoose.js.

Boeschen answered 12/4, 2015 at 18:56 Comment(2)
actually it does make sense in javascript too. I have already worked with client side javascript libraries that follows active record pattern and they just was killing my app util I didnt rewrite the same libraries into data mapper styleKoger
active record and data mapper are completely different patterns with different designs. Doesn't matter if it's JavaScript or Java, the pattern is likely the same.Bequeath

© 2022 - 2024 — McMap. All rights reserved.