Use Range to make sure your reservations don't overlap in Postgres!

  Рет қаралды 6,019

Supabase

Supabase

Күн бұрын

Пікірлер: 51
@dshukertjr
@dshukertjr 6 ай бұрын
I think I will go back to creating Flutter content for the next video. Any other Flutter fans watching this video? What content would you like to see?
@cogulad1067
@cogulad1067 6 ай бұрын
Yes please, any idea for implementing local first apps
@AmmarQ.
@AmmarQ. 6 ай бұрын
❤ Complex RLS or RBAC for flutter app (e.g admin - mod - etc)
@funkdefied1
@funkdefied1 6 ай бұрын
I like the Postgres stuff
@dshukertjr
@dshukertjr 6 ай бұрын
@@cogulad1067 Sounds good. Will explorer the options!
@dshukertjr
@dshukertjr 6 ай бұрын
@@AmmarQ. Love it! Will add it to my list!
@krtirtho
@krtirtho 6 ай бұрын
The best thing to ever happen to postgres is supabase. Without supabase a lof of developer would've missed postgres.
@jamesmoynihan948
@jamesmoynihan948 6 ай бұрын
Perfect timing. I was just about to add some starts_at and ends_at columns! This is a nice feature to learn about!
@Supabase
@Supabase 6 ай бұрын
Awesome!
@LawZist
@LawZist 6 ай бұрын
consider it twice my friend. you may need these columns more then you think
@jamesmoynihan948
@jamesmoynihan948 6 ай бұрын
@@LawZist can you elaborate?
@WestwoodTutors
@WestwoodTutors 6 ай бұрын
@@LawZist Why is that? Genuine question
@LawZist
@LawZist 6 ай бұрын
Im working at a saas company that provide orders delivery optimizations. we work with times A LOT. many times we need to do some logic only on the start time or the end time, do timezones manipulation add or substract times, etc.. im not sure that the range can fit for all these use cases. Im not saying not to use range, im just saying that you need to make sure it is the right solution for your needs, moreover many times we need to do the overlapping check in the backend and it is a very simple check to do
@zzej
@zzej 6 ай бұрын
I’ve struggled with this for a long time. Thanks
@dshukertjr
@dshukertjr 6 ай бұрын
I'm glad to hear that you found it helpful! Let me know if there are any other things that you would like us to turn into a video!
@itscooldawgdonteventrip
@itscooldawgdonteventrip 6 ай бұрын
elite level of pg sql. nice. thanks learning a lot looks like not everything needs to be code. put as much as possible in the db. ( should be faster. )
@dshukertjr
@dshukertjr 6 ай бұрын
Yup! The power of Posgres 💪
@mrrolandlawrence
@mrrolandlawrence 6 ай бұрын
what id love to see is more on the realtime. how to keep your client side JS object the same as your postgres view. including what happens if you miss a channel broadcast because of say network connection issue. from what i understand from the docs if you miss a broadcast message - too bad. there is no queuing for subscribed clients to catch up on?
@dshukertjr
@dshukertjr 6 ай бұрын
Correct. Currently if you miss a broadcast message there is no way of re-fetching it. If it's a data that needs to be re-fetched, you might need to store the information on the DB so that clients that go offline could re-fetch it.
@44galore
@44galore 6 ай бұрын
What would the tstzrange constraint look like if you want to allow maximum overlaps at any certain time. I had to implement this about 15 years ago in Java bizlogic. The use case was to have max 3 top ads active on a webpage at any time for the best sales. They were not assigned to a spot / table only limited by the maximum amount of overlaps at any point in time. Would that be possible to achieve with a postgres db-constraint? - Surely the constraint introduced in the video could be used in a work around / good enough manner by having kind of 3 spots for the max 3 sales but that wouldn't produce a the same UX.
@dshukertjr
@dshukertjr 6 ай бұрын
Great question. Without going into too much details, I think something like this could be achieved using a trigger. Set a trigger on the table when a new row is inserted (or updated if range does get updated), and trigger a function that checks for maximum of 3 overlaps. You can raise an exception from the triggered function to rollback the isnert if condition is not met. supabase.com/docs/guides/database/postgres/triggers
@rageranthem
@rageranthem 6 ай бұрын
Perfect for my project
@torerik1778
@torerik1778 5 ай бұрын
This was so helpful, thanks a lot!
@Supabase
@Supabase 5 ай бұрын
Glad it was helpful!
@thibault7190
@thibault7190 6 ай бұрын
Awesome! In the recent videos you published you talk about constraints, which I think are great to be implemented at database layer. Do you have any advise to handle properly exceptions raised by constraint on client side? How client side can recognize the violated constraint and display the correct friendly message? (with javascript sdk would be perfect 😇)
@dshukertjr
@dshukertjr 6 ай бұрын
The exception raised on the client will contain the name of the constraint that triggered the exception, so looking for the constraint name in the exception and showing different error message depending on the message might be the best way!
@Spacer-l3j
@Spacer-l3j 6 ай бұрын
i'm with Swift and SwiftUI. I have created my brand new project with Supabase as my backend, i'm on week 2 and i love it. I find the Supabase SDK very lightweight compared with Firebase spyware, also very performant and my Previews work wow!... The Supabase Dashboard is brilliant and easy to understand, the only part i need to work on is to learn the basics of SQL as i have never interacted with this programming language and looks like is a must. But even without any SQL knowledge, the default templates does the job with a little of twist here and there. Is .range also used for pagination? For example in SwiftUI we have a List of items and by default it returns 1000 rows from Supabase. Can this be paginated with .range ? thank you
@dshukertjr
@dshukertjr 6 ай бұрын
The `.range()` method in the client SDK and the range data-type that I'm talking about are actually two different unrelated things! The `.range()` method is indeed used for pagination!
@alinagy
@alinagy 6 ай бұрын
Man, the more I get into Supabase, the more I realize Firebase is just not good enough.
@mutesajosh3754
@mutesajosh3754 6 ай бұрын
Supabase is self contained and it's for all seasons.
@dshukertjr
@dshukertjr 6 ай бұрын
Power of Posgres🎉
@mrrolandlawrence
@mrrolandlawrence 6 ай бұрын
noSQL blows. the less optimised your DB is with firebase the more you are going to get charged. not to mention if you were using the postgres geo points extension, you can calculate all your distances without paying for google maps api access.
@alinagy
@alinagy 6 ай бұрын
@@mrrolandlawrenceI don’t mind nosql in general like mongo, but firestore just has way too many limitations that you need to work around. It’s fine for tools or simple apps but anything bigger it is a pain
@jackbrown1260
@jackbrown1260 5 ай бұрын
When can we expect to see support and documentation for these column types in the JS API?
@Supabase
@Supabase 5 ай бұрын
The JS and other client library already supports them, and you can find docs for them in the reference docs! supabase.com/docs/reference/javascript/overlaps
@BonBaisers
@BonBaisers 6 ай бұрын
It's cool, to enforce a business rule that should be on domain layer. But is that really useful to put those kind of constraints on the database ? It blurs the lines between data physical integrity and business logic.
@dshukertjr
@dshukertjr 6 ай бұрын
It's not putting business logic. It's just placing guard rails so that the data stays clean. You should still do validations on your application before inserting the data into the database.
@gustavo-santos-dev
@gustavo-santos-dev 6 ай бұрын
It’s good to have this protection in your DB layer as a complement for your application logic. This means if you see a constraint error in your logs, someone screwed with your application code or might by trying to do a manual update in a wrong way.
@wiesson1546
@wiesson1546 6 ай бұрын
I have never heard of those fields, thanks for that! I’d like to use those features, but postgres syntax is so strange to me.
@BonBaisers
@BonBaisers 6 ай бұрын
@@dshukertjr Actually it is. Data integrity has nothing to do with business logic, it's 2 different aspects. Imagine that your business logic change, you introduce an external flag, should you relax physical constraints on data ? It does not make sense to me. The DBMS should only throw errors if physical integrity is compromised by a transaction. Focus on building and testing your product, not adding more validation layers.
@dshukertjr
@dshukertjr 6 ай бұрын
@@BonBaisers Yup, data integrity and business logic are two completely different things. Different applications have different requirements, so there is no single "correct" answer here, but it's always a good idea to start with more constraints if you are just getting started. One could also argue that there could be multiple applications talking to the database, and it is hard to ensure that all of those applications comply to the same set of rules, where as if the data is secured at the database layer, someone could make a mistake at the application layer and still your data is safe!
@george_davituri
@george_davituri 6 ай бұрын
👍🏻
13min High Intensity Postgres Workout (NO REPEATS)
13:20
Supabase
Рет қаралды 6 М.
Are Multi-Column Indexes a good idea?
11:22
Supabase
Рет қаралды 6 М.
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 222 М.
Pagination in MySQL - offset vs. cursor
13:20
PlanetScale
Рет қаралды 62 М.
I tried 5 Firebase alternatives
10:31
Fireship
Рет қаралды 818 М.
Postgres scales … when you do this!
9:59
Supabase
Рет қаралды 6 М.
Everything you NEED TO KNOW about Relationships
13:53
Supabase
Рет қаралды 4,1 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 376 М.
A Simpler Way to See Results
19:17
Logan Smith
Рет қаралды 119 М.
This is why understanding database concurrency control is important
9:05
Её автомобиль никто не хотел ремонтировать!
20:12
Гараж Автоэлектрика
Рет қаралды 1,5 МЛН
(✋❌)kageihina VS siajiwoo VS meosimmyyt VS oxzung#tiktok #shorts
0:12
Down Spout Catch Basin Installation to French Drain
0:58
Komar Project
Рет қаралды 6 МЛН
Абзал неге келді? 4.10.22
3:53
QosLike fan club
Рет қаралды 31 М.
ПОСТАРЕЛА ЗА 1 ДЕНЬ НА 20 ЛЕТ - МУЖСКОЕ ЖЕНСКОЕ
55:44
ПРИЯТНЫЙ ИЛЬДАР
Рет қаралды 677 М.