品書き
- supabase の Postgres に直接接続する
- supabase pricing
-
データベーススキーマ (テーブル定義) を SQL で確認する
- テーブル一覧
- 各テーブルのカラム一覧
- 各テーブルのプライマリキー定義
- カラムにユニーク制約をつける
-
データベース関数
- updated_at にレコード更新時の日時をセットする
- レコード更新時に更新前のレコードを履歴として別テーブルに保存する
- データベース関数をクライアント (React, Next.js アプリ) から起動する
- exists サンプル
reate or replace function get_suki_umu(user_id uuid)
returns table (ari bool)
language plpgsql
as $$
begin
return query
select exists (
select 1 from comments
where comments.user_id = get_suki_umu.user_id and comments.suki = true
) as ari;
end;
$$;
- トリガーの一覧を取得する
SELECT
a.event_object_table AS table_name
,a.trigger_name AS trigger_name
,a.action_statement AS action_statement
,REPLACE(a.action_statement, 'EXECUTE FUNCTION ','') AS func_name
,b.tgenabled AS trigger_enable
,COALESCE( a.action_condition, '' ) AS action_condition
FROM
information_schema.triggers AS a
LEFT OUTER JOIN pg_trigger AS b ON
a.trigger_name=b.tgname
WHERE
a.trigger_schema = current_schema()
GROUP BY
a.event_object_table
,a.trigger_name
,a.action_statement
,b.tgenabled
,a.action_condition
ORDER BY
a.trigger_name