Re: Is it better keep most logic in the database or the Node.js application?

Поиск
Список
Период
Сортировка
От Laszlo Forro
Тема Re: Is it better keep most logic in the database or the Node.js application?
Дата
Msg-id CAHsHJAgAcsmGiO5RvHYBVRvOOEfk3CAfh8zy3MfCB=tzz5NnMQ@mail.gmail.com
обсуждение исходный текст
Ответ на Is it better keep most logic in the database or the Node.js application?  (Simon Connah <simon.n.connah@protonmail.com>)
Список pgsql-novice
My experience is that
- design your entities and represent them via a view. That means: you may normalize an entity - say, customer entity across tables like 'address' : 'personal data ' etc. various ways. But the view you offer to the client code will be consistent like an API. If your entity representation turns out to be suboptimal, you still can change the table structure and adjust your view but nothing to do in the client code.
- use deterministic data transformations/pure functions in the DB - that is faster, business logic independent, easy to test and you save client code. Such as aggregates, combinations of columns - concatenations, math operators, rolling averages, etc.
The rest I would put into the client code - more business logic related data transformations.
This architecture keeps your DB as an encapsulated domain but also makes it possible to switch the client code.
I hope this helped.
Laszlo

On Fri, Mar 19, 2021 at 8:38 AM Simon Connah <simon.n.connah@protonmail.com> wrote:
Hi,

I've been wondering this for some time but is it better to keep the vast majority of the logic in the database using functions, stored procedures, triggers and everything else or should I keep the SQL in the Node.js web application and use that to directly query the database object? I would have thought using database functions would be faster as the database will know what the query is ahead of time and can perform some optimisations on it but this is just a guess on my part.

What should I do? Keep everything in the Node.js application or do as much as possible in PostgreSQL?

Simon.


В списке pgsql-novice по дате отправления:

Предыдущее
От: Simon Connah
Дата:
Сообщение: Is it better keep most logic in the database or the Node.js application?
Следующее
От: Bzzzz
Дата:
Сообщение: Re: Is it better keep most logic in the database or the Node.js application?