3 reasons you should use Postgres Functions and Transactions

  Рет қаралды 12,093

Supabase

Supabase

Күн бұрын

Пікірлер: 54
@mtmdrew
@mtmdrew 9 ай бұрын
Great video Jon. I just wish there was a better way to organize these functions. Seeing a flat list of functions in the dashboard is what deters me from using them more.
@PERQ1S
@PERQ1S 9 ай бұрын
True
@jpsytaccount
@jpsytaccount 7 ай бұрын
So true!
@Yusuf-ok5rk
@Yusuf-ok5rk 7 ай бұрын
yeah just give us folders and it is 10x better
@parkerrex
@parkerrex 2 ай бұрын
this
@JohnBailey
@JohnBailey 2 ай бұрын
THIS! Yes please organize better
@eleah2665
@eleah2665 9 ай бұрын
Jon is back! He says Dahtah funny! But he sure knows his transactions.
@janglad9136
@janglad9136 9 ай бұрын
While there are obvious performance benefits (and even security ones, especially when accessing your DB from multiple sources) I think it's undeniable the DX for this is much, much worse vs handling this on your server. Both in writing, but also in debugging and maintaining. Wish there could be some progress made on this front.
@joepetrillo6185
@joepetrillo6185 8 ай бұрын
I do agree the DX is much easier when doing this on the application side (more familiar and more code-like, as opposed to SQL). What are all the options for handling this? We have 1 - application side flow (doing repeated sql calls to db and handling responses) 2 - postgres function (this video) do ORMS like prisma just do it like option 1?
@edhahaz
@edhahaz 8 ай бұрын
introducing postgres react procedures... with redux
@JackBrunsion
@JackBrunsion 2 ай бұрын
Bleh i almost throw up when i need to manage my transaction logic from supabase dashboard instead of codebase :c
@charlyyshell
@charlyyshell 15 күн бұрын
Using Prisma for those cases is a good solution, you can create nested writes or use the $transaction api to write your array of transactions. They have an example in /docs/orm/prisma-client/queries/transactions for a similar example of a money transaction where they withdraw and deposit in the same transaction and rollback if it encounters an error.
@luisandrade1291
@luisandrade1291 9 ай бұрын
Calling a db functions inside other db functions makes a single transaction?
@drancerd
@drancerd 9 ай бұрын
Eso es usar el paradigma "procedural" o "funcional", en una base de datos. Yo lo hago todo el tiempo, literalmente manejo todo desde la base de datos, en el frontend solo hay; labels, layouts, textboxs y botones (pocos, porque no confío en los usuarios/humanos). El resto... Desde la vase de datos ❤ (Toma en cuenta que Postgres es una de las bases de datos más pulidas que existen) Entonces... Cuando le haces ing. Inversa a mi App/ programa, solo te encuentras con un cascarón vacío. Y de ahí a romper/hackear el Api y el server... Es un trabajo que bo cualquiera podría llegar a lograr (Sobre todo, si manejaste bien las Funciones y sus argumentos, RLS, Gatillos, Roles, Permisos, etc.) Aunque no lo creas... Con Appinventor + Supabase; e creado "MVP's" más, eficientes, eficaces y seguros que el producto final de un equipo de "programadores", con 160k de usuarios conectados simultáneamente, con más de 40k de transacciones por segundo (con datos ultra confidenciales). [Sin usar autenticación, JWTs, Oauth, etc]. Solo porque se manejarme con la base de datos.
@abhilashpatel6852
@abhilashpatel6852 2 ай бұрын
No
@shanehoban
@shanehoban 9 ай бұрын
Great video. Is there any way to manage these functions via your git repo and have them update on push or merge to master? Now that would make me use them much more and maybe some day will be possible if not already
@wembleyleach
@wembleyleach 9 ай бұрын
It depends on your project setup, but at the end of the day these functions are written in plain SQL in files that live in your project repo, possibly next to all your other SQL scripts. You can use any migration tool you’re familiar with to add them to Supabase. Just make sure to drop the previous version of any function you’re updating before applying the new ones.
@supirman
@supirman 9 ай бұрын
yes, you should be using supabase migrations framework which allows you to easily keep local/staging/prod up to date with your functions and schema changes.
@hipdev_
@hipdev_ 8 ай бұрын
We need a way to sync local Postgres functions with Supabase using the Supabase CLI, it's much better to have them in code locally.
@supirman
@supirman 8 ай бұрын
that's what migrations are for...
@wdavidow
@wdavidow 7 ай бұрын
Struggling to find the documentation around the `client.query` API the way transactions are shown in early part of this video. Is that API documented on the Supabase docs site?
@luisandrade1291
@luisandrade1291 9 ай бұрын
Is it possible to declare a transaction outside of a db function?
@drancerd
@drancerd 9 ай бұрын
Postgre es mi sistema operativo favorito. ❤❤❤
@edumorango
@edumorango 8 ай бұрын
Yes.SQL commit
@francbele
@francbele 5 ай бұрын
Can you use, and does it make sense, to use Postgres functions for Auth table?
@CV-wo9hj
@CV-wo9hj 9 ай бұрын
Thanks Jon. How does putting it inside a function make it into an atomic transaction? What happens if that first insert fails how does it know to roll back?
@michaeldausmann6066
@michaeldausmann6066 9 ай бұрын
This is a great question. I'm not convinced that just putting statements in a function "conveniently" wraps them in a transaction. My understanding was that the function runs within the transactional context of whatever is executing the function. Perhaps supabase RPC begins and commits the transaction? It's important because if the intention of the function is to encapsulate a transaction perhaps it's better to do it explicitly in the function body.
@supirman
@supirman 9 ай бұрын
@@michaeldausmann6066from the postgres docs: PostgreSQL actually treats every SQL statement as being executed within a transaction. If you do not issue a BEGIN command, then each individual statement has an implicit BEGIN and (if successful) COMMIT wrapped around it. A group of statements surrounded by BEGIN and COMMIT is sometimes called a transaction block. so triggering the function executes it within a transaction. It's easy enough to try it out to verify.
@joshuaowusu-ansah5142
@joshuaowusu-ansah5142 8 ай бұрын
@supabase @jon
@flowstatehandle
@flowstatehandle 7 ай бұрын
@@joshuaowusu-ansah5142 would love to hear some more about this feature too, I can't find anything about it in the docs
@theashishmaurya
@theashishmaurya 3 ай бұрын
How do we revert if one transaction fails?
@supirman
@supirman 9 ай бұрын
Great video as always. Thank you, sir.
@xgtwb6473
@xgtwb6473 8 ай бұрын
So no second video on the auth?
@christophernolan8761
@christophernolan8761 5 ай бұрын
A video show how to do table joins in supabase postgres functions would be really appreciated
@ScriKidding-eg6vn
@ScriKidding-eg6vn 9 ай бұрын
the problem is its so sick! to write another language than calling a transaction api like what firebase is doing
@cristianpassos1176
@cristianpassos1176 8 ай бұрын
Hello, how are you? I created a function and I'm calling it using RPC: let { data, error } = await supabase.rpc('get_products_for_establishment', { establishment_id: 1, }); if (error) console.error(error); else console.log(data); But I'm encountering this error: Argument of type 'string' is not assignable to parameter of type 'never'.
@santiagovelezsaffon
@santiagovelezsaffon 2 ай бұрын
Postgres has also a really cool way to tell if the previous query returned null. If not found then
@Shmarti
@Shmarti 8 ай бұрын
This is way too involved. I just want to call a native transaction function from my swift client like Firebase. I don't have time for the rest...
@siyoonjung2879
@siyoonjung2879 Ай бұрын
I don't want to perform business logic in the database function, as it is not good for maintainability.
@hueseyinguendogan8541
@hueseyinguendogan8541 17 күн бұрын
Doing a "rollback" in an "EdgeFunction" would be awesome
@AntonSarg-e5n
@AntonSarg-e5n 5 ай бұрын
I find it way to complicated to create functions and it is such a bad experience. Would be nice to have solution inside the application code. Since those functions also hold valuable information about the logic and what the app actually does.
@nafg613
@nafg613 5 ай бұрын
A bigger issue with the app-side transaction management approach than coding mistakes IMO is there's no guarantee your code completes. Worst case the VM loses power unexpectedly. Although the recent crop of durable execution platforms such as Golem Cloud could mitigate that.
@caseyspaulding
@caseyspaulding 5 ай бұрын
So good! Thanks!
@cnikolov
@cnikolov 5 ай бұрын
One thing Id like to see from ms sql coming to supabase is temporal tables 🎉❤
@codewithguillaume
@codewithguillaume 9 ай бұрын
🔥
@BJRNextCode
@BJRNextCode 8 ай бұрын
He is awesome 💥
@jenialherdianto292
@jenialherdianto292 4 ай бұрын
Slow down just a little bit. Your contents really-really good..
@drancerd
@drancerd 9 ай бұрын
Postgre es mi sistema operativo favorito 😂 ¿Sabías que puedes jugar Doom en Postgre? Y Supabase es palabra mayor ❤ porque solo apareció, de la nada! Y todo aquel que buscaba oro en encontró Adamantium y Vibranium en un solo lugar.
@flanderstruck3751
@flanderstruck3751 4 ай бұрын
¿Qué clase de comentario retardado es este?
@amiraliazimi1464
@amiraliazimi1464 5 ай бұрын
that lower casing ocd
@jerryphm
@jerryphm 4 ай бұрын
tysm
@fastneasy
@fastneasy 9 ай бұрын
I like that he wobbles like a jelly non stop
@ibrahimkouma6751
@ibrahimkouma6751 8 ай бұрын
supabase is the future believe or not
8 things you should NEVER do in a Database!
22:56
Supabase
Рет қаралды 13 М.
Simplify complex SQL queries with Views in Postgres
26:01
Supabase
Рет қаралды 10 М.
УНО Реверс в Амонг Ас : игра на выбывание
0:19
Фани Хани
Рет қаралды 1,3 МЛН
БАБУШКА ШАРИТ #shorts
0:16
Паша Осадчий
Рет қаралды 4,1 МЛН
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 221 М.
You need to aware of this about Supabase
17:47
Daily Web Coding
Рет қаралды 6 М.
Supabase + Next.js ULTIMATE Auth Combo
8:55
The Dev Logger
Рет қаралды 9 М.
This is why understanding database concurrency control is important
9:05
Make your queries 43,240x faster
13:16
Supabase
Рет қаралды 27 М.
Are Multi-Column Indexes a good idea?
11:22
Supabase
Рет қаралды 5 М.
УНО Реверс в Амонг Ас : игра на выбывание
0:19
Фани Хани
Рет қаралды 1,3 МЛН