Earlier quoted context omitted.
>The main problem with raw SQL is that what you really want is a genuine programming language. You almost want programmatic access to the SQL AST, so you can generate syntax as opposed to concatenate strings together. Kind of like a DOM API, but for SQL. What you described is basically EF+LINQ. var query = context.Users.Include("Users.Group").Where( u => u.UserType == UserTypes.Basic).Select( u => u.Group); That's go…
The same in Scala + Slick would be: val q = Users.filter(_.userType == UserTypes.Basic).map(_.group) Although I'm not sure what the context.Users.Include bit in the EF example is doing. Both will generate statement at compile time, and I assume EF queries are composable as is the case with Slick. Slick's readability does suffer though with more complex queries -- unfortunate they strayed away from SQL semantics in fa…
What ORMs have taught me: just learn SQL
121–130 of 245 posts
Re: What ORMs have taught me: just learn SQL
#122I wrote "raw" SQL for many many years before using ORMs, so I feel a lot of this guy's pain and agree with most of his points. Especially the part about still having to know SQL even though you're using an ORM. Not sure I understand his solution to this one, though! Window functions are relatively advanced SQL that is painful to write with ORMs. Not writing them into the query likely means you will be transferring a…
With AR, if this is the worst case where you write some raw SQL, what's the alternative? The alternative seems far more painful pragmatically speaking and this, while being a little ugly, seems to work just fine without impacting productivity or performance.
Re: What ORMs have taught me: just learn SQL
#123Re: What ORMs have taught me: just learn SQL
#124Earlier quoted context omitted.
that's absolutely not true.Sure you cant write a procedure with an ORM. But good ORM have query builders that with allow you not to write ANY sql.At all.ORMs are not just about CRUD at all.
The biggest downside to this that I found is that you have to have a lot of trust in the creators of that ORM. SUre, it will generate a query that gets you what you want - but will it use the right indices? Will use correct ordering for optimal results? Generally (unless this has changed in more recent years) the answer is 'no'.
Re: What ORMs have taught me: just learn SQL
#125Earlier quoted context omitted.
> You almost want programmatic access to the SQL AST, so you can generate syntax as opposed to concatenate strings together. Kind of like a DOM API, but for SQL. I think this is the appeal of MongoDB's driver on Node: You really do have programmatic access to the AST, insofar as the microlanguage is just a plain old Javascript object. Though SQL is more universal, Mongo's approach definitely has thought hard about th…
>Though SQL is more universal, Mongo's approach definitely has thought hard about the balance between abstract and concrete that me and my other developers find very intuitive. I think you've got the causality and conclusion backwards here. MongoDB's easy programming API is a consequence of its storage layout on disk -- the JSON/BSON bytes on disk. From that principle, you naturally get an "ORM" type of API exposed i…
Re: What ORMs have taught me: just learn SQL
#126Re: What ORMs have taught me: just learn SQL
#127Earlier quoted context omitted.
(caveat: I'm a developer but I haven't used ORMs very much.) Don't most ORMs let you write raw SQL when you really want to? In that case, you could use the ORM for simple things, but revert to raw SQL when you need more power. Or is that not the case?
Yes, but the ORM often influences the schema design. That can be very painful down the road when you realize your tables are actually tables, rather than instances of objects, which would be what your ORM led you to believe.
Re: What ORMs have taught me: just learn SQL
#128Earlier quoted context omitted.
> At the very least, it makes the code more portable How writing SQL make your code more portable ? using an abstraction make something portable.SQL implementations are differents from one table to another.
Using an ORM ties you to that implementation. I can more easily take a raw SQL statement and use it elsewhere.
Re: What ORMs have taught me: just learn SQL
#129Earlier quoted context omitted.
This is simply not true, lots of tools are able to tell you exactly which line of code is responsible for which query.
Such as? Using ASP.NET and NHibernate, I've not seen any way to do this other than old fashioned log statements and guesswork.
Worth every penny. You get full stack traces and line numbers automatically with each query.
Re: What ORMs have taught me: just learn SQL
#130Earlier quoted context omitted.
"Object-oriented programming is great. It's what's enabled developers to create the vast world of amazing applications available today. But there's an impedance mismatch between OOP and relational databases. That's why today we're reinventing database access. Say hello to SQL."
If it was released today, they would skip the awkward do-i-spell-it-out-or-do-i-add-vowels part in favor of the catchy-but-meaningless-project-name and just call it Sequel. Then they could be fresh and say it's the "sequel" to ORM. (Though you might go for Seequill or something so people could google it.)