Re:What ORMs have taught me: just learn SQL (2014)
by Animats on Monday December 18, 2017 @03:51AM
(#15950343)
ORMs are more useful as insert builders. Putting data from an object into the database is something of a boilerplate process. Queries vary with what you want to ask. Most of the time, you don't need all the fields, so filling up some object just because it has slots for everything is a waste of effort. Especially if it means references to multiple tables.
[ Parent
| on HN ]
Re:What ORMs have taught me: just learn SQL (2014)
by egeozcan on Monday December 18, 2017 @04:39AM
(#15950510)
Good ORMs have Partial<T> and lazy loading of complex properties through proxies, which can be overridden with something like .With(x => x.ComplexProperty).
But of course, as the queries get more and more complex, the flexibility of the ORM syntax approaches the flexibility SQL. In the end, there are many situations one would rather just use SQL.
Re:What ORMs have taught me: just learn SQL (2014)
by majewsky on Monday December 18, 2017 @04:43AM
(#15950527)
I think the best ORMs are those that just leave out the "Relational" part entirely. So... "OM"?
For example, in Go, I use Gorp, which has a Select() function where you pass in the SELECT query string (plus bound values) and the target type, and it loads every result row into an object of that type. So you can have an arbitrarily complex SQL query as long as it starts with `SELECT one_table.* FROM`. That's a marvelous design.
And when you have to do a query that returns results from multiple tables? Guess what, you just use the normal SQL module from the standard library.
Re:What ORMs have taught me: just learn SQL (2014)
by scarface74 on Monday December 18, 2017 @05:56AM
(#15950797)
Why is it an either or? EF can do that but then you loose the benefits of a type safe language.
Re:What ORMs have taught me: just learn SQL (2014)
by oceanswave on Monday December 18, 2017 @07:45AM
(#15951236)
If type safety is so great, why isn’t sql statically type checked
Re:What ORMs have taught me: just learn SQL (2014)
by majewsky on Monday December 18, 2017 @08:22AM
(#15951402)
SQL is statically type-checked, at least in Postgres.
postgres=# SELECT * FROM domains WHERE id = 'foo';
ERROR: invalid input syntax for integer: "foo"
LINE 1: SELECT * FROM domains WHERE id = 'foo';
^
Re:What ORMs have taught me: just learn SQL (2014)
by cpfohl on Monday December 18, 2017 @08:42AM
(#15951510)
Not just PostGres. That's standard SQL. Columns have data types. Tables have schemata. Schemata are very strongly typed. Can't insert a 'full_name' column into a table without such a column.
Re:What ORMs have taught me: just learn SQL (2014)
by da_chicken on Monday December 18, 2017 @09:02AM
(#15951616)
Unless you're talking about SQLite, SQL RDBMSs are both static and strongly typed. The systems typically do allow some implicit type conversions, but type is critical to how a table works.
Re:What ORMs have taught me: just learn SQL (2014)
by lmm on Monday December 18, 2017 @11:05AM
(#15952558)
Because SQL predates a lot of modern techniques. A ground-up replacement written today probably would be statically type checked.