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

Поділитися
Вставка
  • Опубліковано 15 вер 2024

КОМЕНТАРІ • 51

  • @dshukertjr
    @dshukertjr 2 місяці тому +21

    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 2 місяці тому +5

      Yes please, any idea for implementing local first apps

    • @AmmarQ.
      @AmmarQ. 2 місяці тому +3

      ❤ Complex RLS or RBAC for flutter app (e.g admin - mod - etc)

    • @funkdefied1
      @funkdefied1 2 місяці тому +4

      I like the Postgres stuff

    • @dshukertjr
      @dshukertjr 2 місяці тому

      @@cogulad1067 Sounds good. Will explorer the options!

    • @dshukertjr
      @dshukertjr 2 місяці тому

      @@AmmarQ. Love it! Will add it to my list!

  • @krtirtho
    @krtirtho 2 місяці тому +7

    The best thing to ever happen to postgres is supabase. Without supabase a lof of developer would've missed postgres.

  • @TheBlackManMythLegend
    @TheBlackManMythLegend 2 місяці тому +4

    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 2 місяці тому

      Yup! The power of Posgres 💪

  • @zzej
    @zzej 2 місяці тому +6

    I’ve struggled with this for a long time. Thanks

    • @dshukertjr
      @dshukertjr 2 місяці тому +1

      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!

  • @jamesmoynihan948
    @jamesmoynihan948 2 місяці тому +4

    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  2 місяці тому

      Awesome!

    • @LawZist
      @LawZist 2 місяці тому

      consider it twice my friend. you may need these columns more then you think

    • @jamesmoynihan948
      @jamesmoynihan948 2 місяці тому

      @@LawZist can you elaborate?

    • @WestwoodTutors
      @WestwoodTutors 2 місяці тому

      @@LawZist Why is that? Genuine question

    • @LawZist
      @LawZist 2 місяці тому

      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

  • @LeoMessiEnjoyer
    @LeoMessiEnjoyer 2 місяці тому +3

    Perfect for my project

  • @torerik1778
    @torerik1778 Місяць тому +1

    This was so helpful, thanks a lot!

    • @Supabase
      @Supabase  Місяць тому

      Glad it was helpful!

  • @mrrolandlawrence
    @mrrolandlawrence 2 місяці тому +2

    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 2 місяці тому +1

      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.

  • @alinagy
    @alinagy 2 місяці тому +8

    Man, the more I get into Supabase, the more I realize Firebase is just not good enough.

    • @mutesajosh3754
      @mutesajosh3754 2 місяці тому +3

      Supabase is self contained and it's for all seasons.

    • @dshukertjr
      @dshukertjr 2 місяці тому +1

      Power of Posgres🎉

    • @mrrolandlawrence
      @mrrolandlawrence 2 місяці тому

      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 2 місяці тому

      @@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

  • @thibaultbarolat-massole7190
    @thibaultbarolat-massole7190 2 місяці тому +3

    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 2 місяці тому

      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!

  • @iLoveAppl3947
    @iLoveAppl3947 2 місяці тому +2

    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 2 місяці тому

      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!

  • @44galore
    @44galore 2 місяці тому +1

    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 2 місяці тому +1

      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

  • @george_davituri
    @george_davituri 2 місяці тому +2

    👍🏻

  • @jackbrown1260
    @jackbrown1260 Місяць тому

    When can we expect to see support and documentation for these column types in the JS API?

    • @Supabase
      @Supabase  Місяць тому +1

      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 2 місяці тому

    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 2 місяці тому +4

      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 2 місяці тому +3

      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 2 місяці тому +2

      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 2 місяці тому

      @@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 2 місяці тому +1

      @@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!