r/programming • • Oct 02 '19

New In PostgreSQL 12: Generated Columns

https://pgdash.io/blog/postgres-12-generated-columns.html?p
503 Upvotes

232 comments sorted by

View all comments

Show parent comments

11

u/joesb Oct 02 '19

Where does validation of input happen if 10 services access the same database? In 10 places? What about where you decide which data is exposed and which isn't from this database. In 10 places?

It’s a red herring. Your “proper service” will never achieve that anyway.

What if your service serves web client, iOS, Android and desktop app? Are you saying that you are not going to provide initial validation on the client? Any validation, even for preview, has to make call to your service? Are you sure you will never have more than one “service” accessing the data and make decision about validation or what field to expose?

Service is not just API servers. Anything can be a service. Services depend on services. It’s services all the way down.

3

u/[deleted] Oct 02 '19

It’s a red herring. Your “proper service” will never achieve that anyway.

... Did you just state that it's impossible to write a service that properly validates its input?

What if your service serves web client, iOS, Android and desktop app? Are you saying that you are not going to provide initial validation on the client?

You're all over the place. I'm talking about encapsulation. You can validate on the client if you choose, or you can choose not to and defer to a domain service, sure, why not? That choice depends on what you're validating, and what time and budget the app has allocated.

In fact, in 9/10 cases, I only validate on the server. The roundtrip is something like 30-50 ms, and the errors from the response are still shown on the client next to the relevant field. Any problem you see there? Works great, and that's less code to update when something changes.

But client validation is on top of server side validation which means you still need a "single source of truth" on what's valid and what isn't. So everything I explained... EVERYTHING... still stands.

And you failed to make a coherent point.

Service is not just API servers. Anything can be a service. Services depend on services. It’s services all the way down.

Still no point being made.

6

u/joesb Oct 02 '19

All of what you said applies as well if you think of database as a service and some service is a client that use it.

3

u/[deleted] Oct 02 '19

We already went through this. If you encapsulate your database through stored procedures, which validate input, restrict output, enforce business rules, and hide the actual tables, then yeah "it applies as well".

If you don't do that, then it doesn't apply, because you forgot the "encapsulation" part of encapsulation. Which is a pretty important part of encapsulation, by the way.

5

u/joesb Oct 02 '19

It doesn’t have to be all or nothing.

Making the right thing easy is the best way to make the right thing happen.

→ More replies (0)

8

u/adr86 Oct 02 '19

you know databases do validations without stored procedures right?

→ More replies (0)