Live data from Hacker News

Supabase Wrappers: A framework for building Postgres foreign data wrappers

supabase.com

21–30 of 47 posts

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#21

Earlier quoted context omitted.

Yes, the data is queried live. > unexpected N API calls when joining across my domain I'm not sure why they would be unexpected (because it should displace some other API calls). I'll hazard a guess that you're worried about fetching the same data multiple times? If that's the case, then yes, you should materialize the data into your database. The Wrapper itself handles pagination, but you'd also want to make sure yo…

Thanks for the reply. I'll flesh out my thought process in case it's helpful. My immediate reaction was excitement about the abstraction. An example use case is joining my users to their corresponding Stripe Customers in SQL. The kinds of queries I can reasonably write depend on implementation details of the connector. For example, if Stripe has a bulk customer lookup (list of customer IDs -> Customers), and the conn…

I understand now, and this is a similar problem to how some GraphQL engines work

I imagine you want to do something like:

    select 
        *
    from 
        public.users join stripe.customers
    on
        public.users.stripe_id = stripe.customers.id
    limit 100;
Then yes, it might make 100 consecutive calls to your stripe account. There are 3 options here:

1. Materialize your customers into your database (like I mention in the previous comment)

2. We build a "smart" FDW, so that it parses your query and fetches the Stripe data first, then performs the join.

3. Use a CTE:

    with
    customers as (
        select * from stripe.customers
    ),
    users as (
        select * from public.users
    )
    select 
        *
    from 
        users join customers
    on
        users.stripe_id = customers.id

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#22

So you're telling me I can use this to create my own wrapper to get data directly from another API? I can now use this instead of creating my own workflow to get the data via an api which will be stored in the DB anyways?

yes, that's correct. we've built a read-only version for Stripe (which is API-based), and we aim to have the read/write implementation done soon. You will be able to do something like this: insert into stripe_products (name) values ('Pizza'), ('Pasta'); This will insert a value into Stripe via the API. Then you can query your stripe products like this: select * from stripe_products limit 10;

So I could implement one myself for arbitrary REST APIs?

I can't wait for somebody offering a generator, where you plug in your API, it pulls and parses the JSON, then you can select the fields you want and it generates the wrapper. (Alternatively, for put/post you could supply your own JSON).

Practically like some low/no code tools like Appsmith/Budibase and the likes already do today.

Sadly I lack the necessary skills and more important the time to dive into that.

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#23

Earlier quoted context omitted.

Thanks for the reply. I'll flesh out my thought process in case it's helpful. My immediate reaction was excitement about the abstraction. An example use case is joining my users to their corresponding Stripe Customers in SQL. The kinds of queries I can reasonably write depend on implementation details of the connector. For example, if Stripe has a bulk customer lookup (list of customer IDs -> Customers), and the conn…

I understand now, and this is a similar problem to how some GraphQL engines work I imagine you want to do something like: select * from public.users join stripe.customers on public.users.stripe_id = stripe.customers.id limit 100; Then yes, it might make 100 consecutive calls to your stripe account. There are 3 options here: 1. Materialize your customers into your database (like I mention in the previous comment) 2. W…

4. Use a local http cache in front of stripe's api. This is basically "external materialization".

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#24

Earlier quoted context omitted.

yes, that's correct. we've built a read-only version for Stripe (which is API-based), and we aim to have the read/write implementation done soon. You will be able to do something like this: insert into stripe_products (name) values ('Pizza'), ('Pasta'); This will insert a value into Stripe via the API. Then you can query your stripe products like this: select * from stripe_products limit 10;

So I could implement one myself for arbitrary REST APIs? I can't wait for somebody offering a generator, where you plug in your API, it pulls and parses the JSON, then you can select the fields you want and it generates the wrapper. (Alternatively, for put/post you could supply your own JSON). Practically like some low/no code tools like Appsmith/Budibase and the likes already do today. Sadly I lack the necessary ski…

Yes, I guess it would be possible to works with generic REST APIs - ones that all conform to a similar model.

> generator, where you plug in your API, it pulls and parses the JSON, then you can select the fields you want and it generates the wrapper

Probably on this one the wrapper could use an OpenAPI spec

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#25

I love Supabase and what they're doing! I evaluated them heavily when designing architecture for a healthcare product. I'm not sure about this one though - rust is a great systems language, but it wouldn't be my first choice for bridging the db api gap. I wonder why this wasn't built on top of, or an enhancement to, the existing (excellent) multicorn[1] project. Python seems like a better choice of language for deali…

> I wonder why this wasn't built on top of, or an enhancement to, the existing (excellent) multicorn[1] project

Have to agree with you there, multicorn is extremely cool. I'm a big sqlalchemy fan so their default SQLA wrapper was a killer feature to give up (although maybe we could do something similar with launchbadge/sqlx[1]). We investigated using multicorn early this year and had a few hiccups. Activity on the original repo[2] quieted way down ~3 years ago. For example, pg14 support hasn't landed and the newest supported python version is EOL in 2022. There is new fork[3] with pg14 support (15 in the pipe) that might pick up in adoption but thats still TBD.

Supabase aims to support new major Postgres versions within 2-3 months so we have to be very careful taking on dependencies that might slow that process.

> I'd love to understand more about the technical rationale that drove this.

Architecturally, multicorn has postgres communicate with a separate python process on the host that does all the hard work. That's convenient, but it can bloat over time and/or be memory hungry for larger result sets. The rust implementation runs in-process and is generally a lot lighter.

Currently I'd say supabase/wrappers is a safer/easier version of the C API vs a direct analog to multicorn. Over time I think we'll see that comparison become more appropriate. There's a lot of excitement around the concept internally and we've already been floating some ideas wrt `auto-mapping` tables for common SQL dialects, a generic JSON HTTP API wrapper, etc. Stay tuned!

[1]https://github.com/launchbadge/sqlx [2]https://github.com/Segfault-Inc/Multicorn [3]https://github.com/pgsql-io/multicorn2

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#27
post #26

This seems cool to nerd out to! So thanks for that! But what is the point? Why is this better than making the API call? SQL is for queries, why would I want to do networking with it?

This ends up being a way to hide an ETL pipeline behind a SQL query. Using this and some materialized views it makes it easy to just pull data in from an external source and just have it in your system.

I'm not sure on the value of this for customer facing production systems, but for internal reporting / product analytics this should make it really easy to pull in disparate datasets w/o having to spend eng time to keep each one running.

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#28
post #26

This seems cool to nerd out to! So thanks for that! But what is the point? Why is this better than making the API call? SQL is for queries, why would I want to do networking with it?

This ends up being a way to hide an ETL pipeline behind a SQL query. Using this and some materialized views it makes it easy to just pull data in from an external source and just have it in your system. I'm not sure on the value of this for customer facing production systems, but for internal reporting / product analytics this should make it really easy to pull in disparate datasets w/o having to spend eng time to ke…

Pg newbie here, first time I'm reading about this. Super useful for internal tools indeed!

Could you point me to any tools or resources on achieving that (pulling data from several external databases into a single one for the purpose of analytics/aggregation)?

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#29
post #26

This seems cool to nerd out to! So thanks for that! But what is the point? Why is this better than making the API call? SQL is for queries, why would I want to do networking with it?

Because SQL allows you to better specify what data you're interested in? GraphQL and OData take a similar approach.

Re: Supabase Wrappers: A framework for building Postgres foreign data wrappers

#30

Sorry I couldn't figure this out from the docs, but Stripe data is queried "live" from Stripe, right? The abstraction is great, but won't this lead to unexpected N API calls when joining across my domain + Stripe?

Materialized views enable you to "cache" the response, and only refresh it periodically.
Post reply on HN