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:
const supabase = require('@supabase/postgrest-js')
const meta = new supabase.PostgrestClient('http://localhost:3000', {schema : 'meta'})
const pub = new supabase.PostgrestClient('http://localhost:3000', {schema : 'public'})
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' }
])
let { body, error } = await pub
.from('people')
.insert([ { id: 1, age: 40 } , { id: 2, age: 50 } , { id: 3, age: 60} , { id: 4, age: 13} , { id: 5, age: 19} ])
let { body, error } = await pub
.from('people')
.select('*')
console.log(body);
[
{ id: 1, age: 40 },
{ id: 2, age: 50 },
{ id: 3, age: 60 },
{ id: 4, age: 13 },
{ id: 5, age: 19 }
]
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'
})
let { body, error } = await pub
.rpc('subtract', {a: 63, b: 13})
console.log(body);
50
let { status } = await meta
.from('view')
.insert([
{ schema_name: 'public', name : 'teens', query: 'select * from people where age between 13 and 19'}
])
let { body, error } = await pub
.from('teens')
.select('*')
console.log(body);
[ { id: 4, age: 13 }, { id: 5, age: 19 } ]
-
Doing this for Supabase clients would require:
- installing the meta extension
- adding
meta
todb-schema
- using the
service_role
formeta
calls - adding an event trigger for automatic postgrest schema cache update
-
Some operations could be wrapped by supabase-js to give better DX.
-
The meta extension is pure SQL. So it can be installed on any provider.
- Creating a POLICY
- Creating indexes
- Creating fk constraints
- Creating table privileges
- Create a ROLE