Fork me on GitHub
#sql
<
2018-12-19
>
kulminaator06:12:30

And if mocking around your code is too hard it's a clear and good sign of trouble. Either you are doing too many things in one place or the logic is too coupled. Good time to refactor. :)

💯 4
ccann19:12:40

to touch back on this — got to a great place. much easier to mock, and better separation of persistence and app concerns. Though I’ll admit the very thin added layer of indirection takes a second of squinting

💯 4
johnj19:12:45

many times the business logic is in the database

seancorfield20:12:53

@lockdown- Not in any system I've ever worked on, in 30+ years!

johnj20:12:28

I would argue there's always some kind of business logic in the db

Noah Bogart20:12:31

adding uniqueness constraints is putting business logic in the db

johnj20:12:51

I have seen 100 LoC reduce to five lines of SQL in postgres

seancorfield20:12:51

OK, I'll buy that. (uniqueness constraints)

johnj20:12:31

and can sometimes be more performant

johnj20:12:14

there's just no right answer to this really

seancorfield20:12:13

I don't consider a "blob" of SQL you send over JDBC to be executed as "business logic in the db" tho'. I consider "business logic in the db" to be stored procedures (and, OK, uniqueness constraints).

seancorfield20:12:42

But, yes, doing stuff in SQL from your app can sometimes be more performant than running several "simpler" queries and doing the "logic" in your code. I've also seen the opposite: when a complex query cannot be made more efficient and the DBA asks you to run multiple simple queries and perform that logic in your code 🙂

johnj20:12:25

there's also the isolation issue, when running multiple statements

seancorfield21:12:47

True, and occasionally that can be a real world concern (it hasn't been for us, when we've needed to lift complex SQL operations into concurrent Clojure code to improve performance). And of course there's also transactions -- for the occasions where you need coordination across multiple SQL statements (which is often a lot rarer than people seem to think -- see, for example, Gregor Hohpe's https://www.enterpriseintegrationpatterns.com/docs/IEEE_Software_Design_2PC.pdf )

johnj21:12:37

thanks for the link, was just reading about how github doesn't like FKs https://github.com/github/gh-ost/issues/331#issuecomment-266027731

seancorfield22:12:53

Yeah, our DBA was dead against FKs as well.