Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/poboisvert/duproprio_supabase_rpc

DuProprio to SupaBase for analytics PoC
https://github.com/poboisvert/duproprio_supabase_rpc

nextjs13 postgres rpc supabase

Last synced: 10 days ago
JSON representation

DuProprio to SupaBase for analytics PoC

Awesome Lists containing this project

README

        

# Supabase update or insert (w/JSON)

## .env.local

```
# Development settings
SUPABASE_URL=
SUPABASE_KEY=

```

## SUPABASE FUNCTION

I was having trouble to find documentation on how to save a JSON with RPC function of Supabase

```
CREATE OR REPLACE FUNCTION update_listing_base(page_slug TEXT, address TEXT, data jsonb)
RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
IF EXISTS (SELECT FROM listing WHERE slug=page_slug and is_active is True) THEN
UPDATE listing
SET is_active = True,
updated_at = NOW()
WHERE slug = page_slug;
ELSE
INSERT into listing(slug, address, data) VALUES (page_slug, address, data::JSON);
END IF;
END;
$$;
```

![preview](1.png)

And you can run the query in the interface to validate

![preview](2.png)