News for hackers. Stuff that matters.
Re:To ORM or Not to ORM by dragonwriter on Tuesday May 07, 2019 @04:26PM (#19853131)
> Say for instance we have one query that finds eligible bachelors near me and another that finds newly eligible bachelors. We need two queries but they both rely on the same underlying domain concept of "eligible bachelors". [...] It's hard to do that in sql in a maintainable way.

Seems a textbook case of using a view for sharing query logic.

> If I decide to change a datetime field called time to split it into a datetime and offset that change is far safer in c# than it is SQL.

If you can do it in C# instead of SQL, you must be talking about a change in the interface used by an app (so, with good DB design, a view, not a base table). But this is very safe in SQL, you are changing a view definition and, if its a read/write view, insert and update triggers.

Re:To ORM or Not to ORM by Dayshine on Tuesday May 07, 2019 @05:44PM (#19853729)
>Seems a textbook case of using a view for sharing query logic.

Views are just terrible outside of data analyst style work. Unmaintainable, restricted to SQL structures, require absurd hacks or custom dlls, not properly source controlled, difficult to perform performance analysis on, hard to update.

You can't combine views easily, you can't cache results, you don't get static type checking.

Re:To ORM or Not to ORM by dragonwriter on Tuesday May 07, 2019 @06:35PM (#19854076)
> Unmaintainable,

Views are not "unmaintainable".

> restricted to SQL structures,

I'm not sure how that's a problem, since SQL is a fully-general data language.

> require absurd hacks or custom dlls,

Views require neither hacks nor "custom DLLs" in any RDBMS I am aware of. Can you provide a concrete example?

> not properly source controlled,

There's no reason DB schemas (including, but not limited to, view definitions) can't be source controlled.

> You can't combine views easily

Yes you can, whether by "combine" you mean as joined source relations, or as criteria that need to be combined to slice and dice the same source data. That's, like, playing right to the strength of SQL and RDBMS systems.

> you can't cache results,

Well, not generally incrementally or in something like a recently-used cache; a number of RDBMS's do support materialized views, though.

Re:To ORM or Not to ORM by GordonS on Tuesday May 07, 2019 @06:05PM (#19853887)
I don't like to say "you're doing it wrong", but TBH it sounds like you are.

> restricted to SQL structures

So is your ORM; it just adds a layer of abstraction

> require absurd hacks or custom dlls

Literally no idea what you're doing that views require anything out of the ordinary, or indeed "custom DLLs"

> not properly source controlled

Eh? You can store your view DDL files in source control just fine. I mean, they're just SQL files; why couldn't you?

> difficult to perform performance analysis on

I don't see how ORMs offer any advantage here - if anything, SQL has the edge here, since your typical SQL GUI will draw pretty graphs to help visualise EXPLAIN, and some (e.g. SSMS) will even suggest missing indexes

> hard to update

It's just SQL, and for views typically rather basic SQL at that.

I use ORMs on 99% of the projects I work on, sometimes heavyweights like Entity Framework Core or Marten (which I love, BTW), and sometimes more lightweight like Dapper - but I know when to use the right tool for the job, and sometimes that's SQL views. I just don't get any of your arguments against them.

Re:To ORM or Not to ORM by strokirk on Tuesday May 07, 2019 @06:11PM (#19853929)
What SQL GUIs do you use that draws graphs for EXPLAIN statements? The ones I've used for OSX (PopSQL, Sequel Pro, TablePlus) hasn't had that feature. Haven't used MySQL Workbench in a few years, so not sure about that one.
Re:To ORM or Not to ORM by sigstoat on Tuesday May 07, 2019 @07:22PM (#19854385)
Re:To ORM or Not to ORM by GordonS on Wednesday May 08, 2019 @02:43PM (#19861710)
I mentioned SQL Server Management Studio (SSMS), which is a great GUI for SQL Server. There is also pgAdmin (both 3.x and 4.x have this feature), and it's also available in Azure Data Studio (for SQL Server; it's coming soon for the Postgres version).
Re:To ORM or Not to ORM by GFischer on Wednesday May 08, 2019 @10:26AM (#19859065)
At least for MS SQL, code is fully source controllable, I have it on Git and we have all automated deploys and niceties.

Views can be a problem from a performance side, Oracle has materialized views but MS SQL lags behind (I think Postgre has them too).