Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNGO1-00087u-On for pgsql-novice@arkaria.postgresql.org; Fri, 19 Mar 2021 14:46:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lNGO0-00070v-NG for pgsql-novice@arkaria.postgresql.org; Fri, 19 Mar 2021 14:46:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNGO0-00070n-Fq for pgsql-novice@lists.postgresql.org; Fri, 19 Mar 2021 14:46:00 +0000 Received: from mout.gmx.net ([212.227.15.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNGNv-0002uG-Lf for pgsql-novice@lists.postgresql.org; Fri, 19 Mar 2021 14:45:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1616165151; bh=/OS8kFx3RGObluoDcg3P+3DFi4dZyVbnkvMnt2zqxMI=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=A4eeRKpbx6K9Y8ui+KiMtogKsnrUPWfx4cyxXkNaAXHd1z46Tweuc2NyAdEifrm95 0iC6em2tNF3GFaMBoqvbASC910QvyL/GYW2W5v5s2kdW/5JzdYVyGkd337ruxrS3dg mHThNAd8aNxXveCIWV5rMHgzKfYJW3JYYA8/nfmc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mail.defcon1.lan ([93.15.31.113]) by mail.gmx.net (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MzyuS-1lZpkX1s4E-00x48i; Fri, 19 Mar 2021 15:45:51 +0100 Date: Fri, 19 Mar 2021 15:45:49 +0100 From: Bzzzz To: pgsql-novice@lists.postgresql.org Cc: Simon Connah Subject: Re: Is it better keep most logic in the database or the Node.js application? Message-ID: <20210319154549.173d0923@msi.defcon1.lan> In-Reply-To: References: Organization: Anyone, anywhere BUT in banana demokratik republik of france and UERSS. Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:gGsgdAfEgiSSlko9syKMDsK6QmlJlRLTHZW7ffIVaQdr4+65lix 3t9vaf6LaPpYQxHYcaNxpsDzxeXEWvMfFuQFDiUQ4YYp/p6CPkr9F7JsqbYPjWh/JZEEg+t rBI2Z2yrgeuvmkxksloKtpRii+xM2qtpS6QSsp1v584NQiGg4KunyDHIwdkYMp+Vp26im+r 15TYKWIDXvKLFQkIiyb2Q== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:06UgQ326J6M=:mjLGIj5OaGejTj0lfYAb2+ kuIwMW54KKSHhNGSzdZJDSq19+5Usfk5tvipa2rzEpv7UCxBNOSOef6kns9/qkLcKTXD8TbjN oMPcqFsk54mSKOX3A7p54MSSQsmR9eNhXT8AyVDW6Gw7hsmb6lqwFme6QlAqoygLy42QqANs7 oE2a9drt0/kNcPO+5L26lC3MGTo6El6bk+KJ8YUrk5JKSLk85lRmBCOU/GG0IOQhWLy+1501N jr29dXufM+d0ONVRtitQcA0yeaBw0GePRxM83TnZVDPP3G0/8QjwllbpXXzPHGL37WcPLcA2q sJemLqpYBCklZK9yhpthlhbD7HqzJzla68p/TfAViqmAWgMenIXJfeOkJs19pfTPsqOYWppsQ CsyP09njHjM1IJ/r8VRahhBKTRIOm/p7s5HUDZCQY4q/8vENthLMzLmQDgMIrgwUJH+v40bz9 +sPbA8KThdlj7ZCjIc2uakrQnxI5FXi4fO+jptFPc3kvI3/dnPlt6GAqwzPCzsmI0BEy4Kjcx Y+EGjB6aDEDC69aZWVF+Z6qLcxTazt0PwkIt36JvcMv9BtI5dHP+/l+ivQBANf9lmHbECLU7v E+W6csKcsoA7quQZO0La4Xck8qyaX1hBR+v0K8Yk727uMDZElB7UrOfinE6Zw3Hs33/qzVqVH g9xVaHqNqyvRjAUa2EaC2Ukef1y+9v3XPgq60rbMyWMm9wDBPJPo2zdlopGP5//MygxVD2/EK iVIvnOL6d2g3NliyIjoTGRMTjexT+GTL5dpSrvUaJsku0TSdWmqrwzGp4NRhwR44QyssBt3ij XFjcsOfoNERv2xmpL/SfAVnvSWK+svv1t5bF1JxQpzJlsxmJcUFsaL3DuxQ25jYutTqvd+lBA wL4UqewCt5RrWQvWmgnw== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 19 Mar 2021 08:37:48 +0000 Simon Connah 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. > =20 > What should I do? Keep everything in the Node.js application or do as > much as possible in PostgreSQL? TL;DR : it depends on the kind of your app. Read these links: https://www.postgresql.org/message-id/CAHyXU0z4BKZm324JGEj50LL6_YOeyk514H6d= YRr3TbYiA8DCNQ%40mail.gmail.com https://vertabelo.com/blog/business-logic-in-the-database-yes-or-no-it-depe= nds/ (IMHO, one of the best article there is on this subject) Rule of thumb: if it is a very simple app, use the code, otherwise, use the force, Luke DB own language=C2=A0; in either cases, think twice about your relational model to avoid touching it later. Jean-Yves