Skip to content

Instantly share code, notes, and snippets.

@steve-chavez
Last active January 13, 2026 09:46
Show Gist options
  • Select an option

  • Save steve-chavez/c7e99bc5d8e7acba7166dbf108f7e18f to your computer and use it in GitHub Desktop.

Select an option

Save steve-chavez/c7e99bc5d8e7acba7166dbf108f7e18f to your computer and use it in GitHub Desktop.
Metarest: create database objects from Supabase client libs

Metarest(work in progress)

The main idea is to allow users create database objects through Supabase client libraries. To get a similar feel to firestore.

This can already be done by using meta/[meta_triggers]) + PostgREST.

Some examples with postgrest-js:

Creating a table plus columns

let meta = new supabase.PostgrestClient('http://localhost:3000', {schema : 'meta'})

let { status } = await meta
  .from('table')
  .insert([{ schema_name: 'public', name : 'people' }])

let { status } = await meta
  .from('column')
  .insert([
    { schema_name: 'public', relation_name : 'people', name : 'id', type_name : 'integer' }
  , { schema_name: 'public', relation_name : 'people', name : 'age', type_name : 'integer' }
  , { schema_name: 'public', relation_name : 'people', name : 'score', type_name : 'integer'}
  ])

Creating a function

let { status } = await meta
  .from('function')
  .insert({
    schema_name: 'public', name : 'subtract',
    parameters: ['a integer', 'b integer'],
    return_type: 'integer', language: 'sql',
    definition: 'select a - b'
  })

Creating a view

let { status } = await meta
  .from('view')
  .insert([
    { schema_name: 'public', name : 'teens', query: 'select * from people where age between 13 and 19'}
  ])

Comments

  • Doing this for Supabase clients would require:

    • installing the meta extension
    • adding meta to db-schema
    • using the service_role for meta calls
    • adding an event trigger for automatic postgrest schema cache update
  • Some operations could be wrapped by supabase-js to give better DX.

  • TODO:

  • Creating a POLICY

  • Creating indexes

  • Creating fk constraints

  • Creating table privileges

FROM postgres
RUN metaDependencies="git \
ca-certificates \
build-essential" \
&& apt-get update \
&& apt-get install -y --no-install-recommends ${metaDependencies} \
&& apt-get install -y build-essential \
&& apt-get install make \
&& cd /tmp \
&& git clone https://github.com/aquametalabs/meta.git \
&& cd meta \
&& make \
&& make install
&& cd /tmp \
&& git clone https://github.com/aquametalabs/meta_triggers.git \
&& cd meta_triggers \
&& make \
&& make install
#CREATE EXTENSION hstore SCHEMA public;
#CREATE EXTENSION meta;
#CREATE EXTENSION meta_triggers;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment