"I much prefer to keep the data definition in the database and read it into the application. It doesn't solve the problem, but it makes it more manageable. I've found that reflection techniques to get the data definition are not worth it and I succumb to managing the redundancy of data definitons in two places." My experiency is almost the oposite of that. I've found that automatic migrations are one of the best feat…
What ORMs have taught me: just learn SQL
111–120 of 245 posts
Re: What ORMs have taught me: just learn SQL
#112I think what's going on here is that elementary mapping of objects to and from relational tables is really easy and obvious, so people go ahead and implement it. Unfortunately once you get past the easy bits and have to worry about breaking objects across tables, foreign keys, transactions, caching, and other fun stuff, you have a great big mess and you probably messed up some of the edge cases.
Re: What ORMs have taught me: just learn SQL
#113Over and over I keep finding that just an ORM is not enough, but raw SQL is hideous in a different way. ORMs map nicely when you are indeed modifying objects, but somethings don't map well that way. So don't map them that way! What we need is a low level abstraction layer alongside the ORM. The main problem with raw SQL is that what you really want is a genuine programming language. You almost want programmatic acces…
>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…
And then if you're a control freak, feed that generated query into ScriptDom [1].
[1] http://msdn.microsoft.com/en-us/library/microsoft.data.schem...
Re: What ORMs have taught me: just learn SQL
#114Earlier quoted context omitted.
Is there something like YeSQL for Go?
Not that I've seen, but I've love to see it. You could probably build it with something like text/template and write: SELECT id, title, expiry_date FROM posts WHERE id = {{ id }} AND expiry_date > {{ date }} ORDER BY expiry_date This would give you some flexibility--the template tags would be replaced by ? or $1 or :name depending on the database driver set on parse--and leans on the stdlib. This would tie in nicely…
Re: What ORMs have taught me: just learn SQL
#115Re: What ORMs have taught me: just learn SQL
#116ORMs are great for simple CRUD operations. As soon as you want to do anything mildly complex or desire efficiency, you need to write SQL. As long as the ORM helps me with the former and gets out of my way for the latter, I'm totally happy to utilize then.
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.
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
#117Earlier quoted context omitted.
If you're at all interested in opening a kick starter for such a templating library for Django, I'd back it. I have attribute creep all the time and actually generally prefer raw SQL with the exception of its verbosity. The problem is, migrations are awful and SQL injection mistakes easy to come by. Would be great to have the best of both worlds in a SQL templating engine + sort-of ORM wrapper that auto-generates via…
Without the ORM, though, what would be the point of using Django? To me it seems like this would be a better fit for a more minimalist platform like Flask.
Re: What ORMs have taught me: just learn SQL
#118Great article!
Re: What ORMs have taught me: just learn SQL
#119I used to write raw SQL for many years, then, around 2005 switched over to ORMs in order to be able to target different databases, have a nice model, etc. Lets be honest here, the ease of justing doing: p.username = "Carl" p.age = 33 p.save instead of "update users set username=:username, age=:age where id=:id" has a ton of advantages. For one, some sort of syntax or type checker is actually trying to understand your…
Is there something like YeSQL for Go?
getUser, _ := db.Prepare("select * from users where username=$1 limit 1")
row := getUser.QueryRow("john")Re: What ORMs have taught me: just learn SQL
#120Over and over I keep finding that just an ORM is not enough, but raw SQL is hideous in a different way. ORMs map nicely when you are indeed modifying objects, but somethings don't map well that way. So don't map them that way! What we need is a low level abstraction layer alongside the ORM. The main problem with raw SQL is that what you really want is a genuine programming language. You almost want programmatic acces…
>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…
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 favor of Scala collections. We'll see where it goes...