/
dmukhin
/
SpherePlatform
Обзор
Документация
Войти
/
dmukhin
/
SpherePlatform
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
db/init/01_sphere_functions.sql
70 строк
2 KB
OIS\sabogdan
first commit
24 мар 2026, 07:50
24 мар 2026, 07:50
b0e18c7
Код
Авторство
О чём код?
-- Sphere helper RPCs (PostgREST). Safe to re-run. -- Mirrors repo root exec_sql.sql — keep in sync when changing functions. drop function if exists public.exec_sql(text); create or replace function public.exec_sql(sql text) returns jsonb language plpgsql security definer set search_path = public as $$ declare normalized_sql text; begin if sql is null or btrim(sql) = '' then raise exception 'SQL is empty'; end if; normalized_sql := lower(regexp_replace(sql, '^[[:space:]]+', '', '')); if normalized_sql !~ '^create[[:space:]]+table([[:space:]]+if[[:space:]]+not[[:space:]]+exists)?[[:space:]]+' and normalized_sql !~ '^drop[[:space:]]+table([[:space:]]+if[[:space:]]+exists)?[[:space:]]+' and normalized_sql !~ '^alter[[:space:]]+table[[:space:]]+' then raise exception 'Only CREATE TABLE / DROP TABLE / ALTER TABLE are allowed'; end if; execute sql; return jsonb_build_object('ok', true); end; $$; revoke all on function public.exec_sql(text) from public; grant execute on function public.exec_sql(text) to anon, authenticated, service_role; drop function if exists public.list_public_tables(); create or replace function public.list_public_tables() returns table(table_name text) language sql security definer set search_path = public as $$ select t.tablename::text as table_name from pg_catalog.pg_tables t where t.schemaname = 'public' order by t.tablename; $$; revoke all on function public.list_public_tables() from public; grant execute on function public.list_public_tables() to anon, authenticated, service_role; drop function if exists public.list_table_columns(text); create or replace function public.list_table_columns(p_table_name text) returns table(column_name text, data_type text) language sql security definer set search_path = public as $$ select c.column_name::text, c.data_type::text from information_schema.columns c where c.table_schema = 'public' and c.table_name = p_table_name order by c.ordinal_position; $$; revoke all on function public.list_table_columns(text) from public; grant execute on function public.list_table_columns(text) to anon, authenticated, service_role;