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 1lNKwk-0002ja-7z for pgsql-novice@arkaria.postgresql.org; Fri, 19 Mar 2021 19:38:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lNKwj-0007DY-5P for pgsql-novice@arkaria.postgresql.org; Fri, 19 Mar 2021 19:38:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNKwi-0007D4-UE for pgsql-novice@lists.postgresql.org; Fri, 19 Mar 2021 19:38:08 +0000 Received: from mout.gmx.net ([212.227.17.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lNKwf-0007gN-QT for pgsql-novice@lists.postgresql.org; Fri, 19 Mar 2021 19:38:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1616182684; bh=VuCCBE6fGTAnsyv61kTD70JhGbyrSt/ewv/0khVJFZ8=; h=X-UI-Sender-Class:Date:From:To:Subject:In-Reply-To:References; b=AUFl2Em4PQrFNJPhuD/7eb6oA+TkGWtuqK7beFAtOhFgaAjvuHBqXCKEF7wmlK4F5 Wnk3a+HsyDaG3pv8CpuY52E7HM8zcDS/tyavrf4ss4Ok6nDTRBWARQu+kTL4pm3sMn bNNkjTTgHHtXa3JJVu1MWkbI1hvkyHCJJ7JFcgBY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mail.defcon1.lan ([93.15.31.113]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mdvqg-1lvqPq0U4M-00azfI for ; Fri, 19 Mar 2021 20:38:04 +0100 Date: Fri, 19 Mar 2021 20:38:01 +0100 From: Bzzzz To: pgsql-novice@lists.postgresql.org Subject: Re: Is it better keep most logic in the database or the Node.js application? Message-ID: <20210319203801.788e224f@msi.defcon1.lan> In-Reply-To: <_mfPnMS1u4MuZo4RbRpPJcRPW2eSbqUyYqZvJZQ-GNzxbus55FF-CHIwd7SY-gNTbY4LRjieTCGKMauoCgafMzdFJjHU0JDctjta_AkeXCU=@protonmail.com> References: <20210319154549.173d0923@msi.defcon1.lan> <_mfPnMS1u4MuZo4RbRpPJcRPW2eSbqUyYqZvJZQ-GNzxbus55FF-CHIwd7SY-gNTbY4LRjieTCGKMauoCgafMzdFJjHU0JDctjta_AkeXCU=@protonmail.com> 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:FfpJKyxRyZ5Jph14Fg32s3JnBqlWwKTp31RCCRmWcMfPXFVBbRD i8xXkIZzNb5Hp2UxXycUlMcu8S7rC+8eG5r9AEqHZ3W5z0Ot5RpXJ6OXL19cunSDSk0GXV2 O+hx9Sl7RQBkE53gPpz6Z0s8GZlZ45Gvtjdm589l7AhE3eJpR9F1FMIb966vKSvL+mEYV5k YcXBwzMTYk+PZXWs/rTLg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:VVTDuyMTWIw=:TDyqkc1YQ7rCcMIuhXjp04 7+qh/CcrYh+WG0G6sNsrvWzQYQVXgvxPhBsJ6BYvez7nFSWNWjkjgBUxX88JBePDLiwTg7hGB /gLMjJwTfZ0vIF4Bewe1ikfj1vgc6FJTjZmqd1tbwlQR5WJiCWoeajbrbM45Ym2xezBsY/MBz +WNocgqN/kF79Vrr3ObY0DkVlW5Z1fUbxacv1lkhA0j/DosQcUWx+U/9Wl22M2cuEAWNHg1cR zMVZCJl+cgavxHfr55s+RWd8pe6Mt1FgN/au3B+ofQiFK4pNeOHv/J+idPq0bywwLTyipyEHJ Cg99faL2gIt4GrSizwKNs0dlJtrHNvJQ9/UB/8M5om2Jr40gSD1KKZNogYdpavGtz3R1bmbZR 7w54Uc491NsDMNxvUnNQNisQ7bXx470IhQk9dmz6Z6k+KnwruaBg2jKYZE+zARmEhq41msUc8 ufHUgrBP/Wf3SrG34RPhQI25tQm30Hm1OCehKc8ZBUEt5iku8v1aNeuzh5y3sbIPYEEeSPmov PmEq9ATiU/DkvCUMUEtVMrL9zzv3lx0dxBbgfYgUHEzn41WgJ6nF0afV8jDyimK89pGFI4EL8 NadC0W3NFH5rFHeSuAPpORic69nMWWTB6Th+c1MmnAqTkf97TNddkZGOhThH3z6uOKi6FyPXV BIkyrX19BI9DSWgN2m2uQpOGfKeTDX0EpnUaudYJNdKW4sbeeFO+pwygjEnpkQUTDIEBN96ux bZ/R2SmrumMry8zKoF5C8Jbtpms6u7/oImZmhaGd8I4ob1qXs6hhRhNYiYWeg7D4dDEi+5e+M +obX0uc9DRvD/XODcuNMUhiaA4+95f8apSJbWvc/iY8jL4Nszimut08d4pvQgLELFT7TE9qPz 6AFf20l4I5Wtgn8vp7NJhpvE322FdEj662yfzP5m3gBGyIaoyvivjGkV+UIoO+Z//JvlAwvXT VTMn96vqyQPus4MVkNhSmo33rj+qa8gsyhQtFPHyk3JMb+XeggeGno+nPMIHGRkH28uvmQpb3 IHlstEtHyNjleZOUuYtTKUj6eNW9uKtrcNu4vZtB0/ZLAMVGtFDtHu8mRIzZYw5769c3jNpFM 4aAsirKNyPyPP1lzpZtgRC3yq7vOP+tfYYiptK06jSSe7iOVFpipAwGldT8IoaQGq75AGRzuU yzmgtkRLm5pR/BKe0YDulkHtCpWwjrylQqtDcDHnJL+pb6xXVW2iAp/klNApVToTDN7Zs= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 19 Mar 2021 19:08:58 +0000 Simon Connah wrote: >=20 >=20 > =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original = Message =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 >=20 > On Friday, March 19th, 2021 at 14:45, Bzzzz wrote: >=20 > > On Fri, 19 Mar 2021 08:37:48 +0000 > > > > 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? > > > > TL;DR : it depends on the kind of your app. > > > > Read these links: > > > > https://www.postgresql.org/message-id/CAHyXU0z4BKZm324JGEj50LL6_YOeyk51= 4H6dYRr3TbYiA8DCNQ%40mail.gmail.com > > > > https://vertabelo.com/blog/business-logic-in-the-database-yes-or-no-it-= depends/ > > > > (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 >=20 > Thank you for the links they were really useful. You're welcome! > I'm building a > blogging platform so it is not a super complicated application > although there are some features there that could complicate some > parts of it. I think I'm going to try and keep as much in the database > as possible. It'll make the application code much easier to follow > without loads of SQL to figure out and to add. Try to avoid composite programming at all cost : 1 year later, you won't remember where this or that is - into the code or into the DB. I've tested all business logic into the DB with an app that makes reservations ; at first, I was ranting because of=E2=80=A6 my own fault (mo= stly by adding features during coding) but at last it was very comfortable : the DB's doing what it is good at (procedures, Fn, ruling user's permissions, etc) and code only interrogates it through the API, avoiding completely middleware/backend - moreover, there is no possibility for clients to directly reach tables/views=C2=A0; at the beginning, it was possible but I rapidly saw it was lame for the above reason and the Fn/procs overhead is not that large that it is blocking (especially after the 1st call). Ah, I found the bookmark I was looking after at first, also read this : https://gnuhost.medium.com/stored-procedures-as-a-backend-c5d2db452fc2 Jean-Yves