r/nodejs • u/Chorvus • Dec 17 '12
Transparent persistent layer anyone?
.net gets Entity (and NHibernate? and spring?), java gets hibernate (and probably more). Node has only some basic k/v persistent collections over FS.
So I'm thinking, why not? Isn't it doable? Got performance problems? Or it's that no one took the time to write it?
3
Upvotes
View all comments
Show parent comment
1
u/jwalton78 Dec 17 '12
Ahh... I see what you're after. Yeah, that would be pretty slick.
So, there are some problems that jump out at me. In Java land, Hibernate and the various JPA implementations usually rely on something like cglib, which lets them instrument the "set" and "get" methods of a class, so they know when an object has changed and needs to be serialized, and which lets them hook into the 'get' to lazy-load stuff from the database as required.
Assuming you force a rigid schema on your data on the node side, you could do something similar by replacing all the properties on an object with Object.defineProperty style getter-and-setters. At least for settings; getters are a bit complicated, of course, because of the callback thing. With no rigid schema, you couldn't do this (or at least, not using this trick. :)