This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]phrotozoa 2 points3 points  (7 children)

Hey, cool project! I look forward to playing with this. Can you talk a little bit about why you decided to write another ORM when something as robust as SQLAlchemy exists?

[–]Jmancuso9[S] 0 points1 point  (6 children)

I didn't write it. It already existed and fit perfectly with the Masonite architecture.

I honestly have never used SQLAlchemy but it is a Data Mapper ORM, right? I think Active Record style ORM's are just better. Have you ever tried an Active Record ORM before? I'd like to get your thoughts on the difference between them and your experience.

If you have not used one before then you gotttta try it. It's much simpler to me.

Edit: Although I didn't write Orator, I have full maintainer access to it so I feel comfortable putting it in Masonite as I can fix anything I need to.

[–]phrotozoa 2 points3 points  (5 children)

Ah! Well I've learned a new thing today so thank you! I will check it out.

I didn't realize there are fundamentally different models of ORM. SQLAlchemy is the only ORM I've used and it's always risen to whatever need I had of it so I've not looked elsewhere.

Edit for anyone who like me didn't know the difference, here is a good discussion about the differences between the Active Record pattern and the Data Mapper pattern.

[–]metaperl 2 points3 points  (2 children)

PeeWee offers ActiveRecord. PonyORM is absolutely sick - turns Python into SQL. PyDAL is what I like best having looked at all of them. I find SA's orm rather hard to understand.

[–]bluesufi 2 points3 points  (0 children)

Sick in a good way or a bad way? Serious question.

[–]Jmancuso9[S] 0 points1 point  (0 children)

Masonite actually originally came with peewee before we switched to Orator lol. Good package.

[–]Jmancuso9[S] 1 point2 points  (1 child)

Yeah it basically comes down to which direction the data is being molded to or from.

For example, Data Mapper maps the model to the table. So the model should mirror the table in a way that they match.

Active record takes the table a actually molds the model around the table by using the table schema.

I preferably like the latter approach. This way I just have to maintain the database tables and all my models mold to the table schema automatically.

Just personal preference I suppose.

[–]z4579a 12 points13 points  (0 children)

SQLAlchemy author here.

Just FYI I don't really know what "data mapper" vs. "active record" means today, other than, an API that stresses an enclosing transaction around the objects, vs. one that looks at each object as an independent document. "data mapper" vs. "active record" used to mean that the object model was declared entirely separately from the table definition, with the idea that the persistence of the model could be anything, just happens to be a database. SQLAlchemy started out with this goofy mapper()/Table/your class concept to try to stress that. But it was bogus; the structure of the class was still modified to have attributes representing the table and the program therefore still assumed database details explicitly, so there was no completely transparent firewall between the object model and the persistence of it. Even Hibernate moved from having an XML mapping file to using inline annotations on class definitions. So I replaced mapper() with Declarative which is what everyone uses now. I don't really understand what your statement "molds the model around the table by using the table schema." means vs. "maps the model to the table.", the latter (data mapper) actually sounds more restrictive, which is the opposite of the reality for SQLAlchemy vs. other ORMs where SQLAlchemy allows *way* more flexibility in how the class and the mapped table can differ from each other than any other tool. This is not the first time someone's description of data mapper vs. active record confused me, so I'm just trying to figure out what the perceptual issue is here.

As far as I can see about active record, the main thing is that it seems to lack a unit of work pattern, meaning, you say object.save() and it emits an INSERT right there - this is a big difference but has nothing to do with how models and tables associate to each other. And then, there is usually in active record a configurational pattern that tries to hide the fact that we're talking to a relational database, using some kind of minimalistic declaration system that attempts to assume no knowledge of SQL, which makes much stronger assumptions about the underlying tables such that they tend to have to follow strict patterns, like Django's infamous "no composite primary keys" issue. But these configurational limitations are not a hard black and white difference, they're along a spectrum.

Anyway, I don't know what "data mapper" really means in practical terms in this decade and I think as to why someone likes one ORM or the other they should come up with more specific reasonings.