{"id":16265968,"url":"https://github.com/zernonia/supadb","last_synced_at":"2025-03-19T22:30:35.355Z","repository":{"id":42013186,"uuid":"478387062","full_name":"zernonia/supadb","owner":"zernonia","description":"Connect and play with Supabase REST API / Graphql easily","archived":false,"fork":false,"pushed_at":"2022-04-22T02:43:25.000Z","size":1710,"stargazers_count":46,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T21:14:17.784Z","etag":null,"topics":["graphql","rest-api","supabase","vite","vue3","windicss"],"latest_commit_sha":null,"homepage":"https://supadb.dev","language":"Vue","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zernonia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":["https://www.buymeacoffee.com/zernonia"]}},"created_at":"2022-04-06T03:21:51.000Z","updated_at":"2024-12-25T08:13:49.000Z","dependencies_parsed_at":"2022-07-22T19:33:24.903Z","dependency_job_id":null,"html_url":"https://github.com/zernonia/supadb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"zernonia/vite-haste","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zernonia%2Fsupadb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zernonia%2Fsupadb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zernonia%2Fsupadb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zernonia%2Fsupadb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zernonia","download_url":"https://codeload.github.com/zernonia/supadb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244022653,"owners_count":20385134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","rest-api","supabase","vite","vue3","windicss"],"created_at":"2024-10-10T17:21:17.301Z","updated_at":"2025-03-19T22:30:34.906Z","avatar_url":"https://github.com/zernonia.png","language":"Vue","funding_links":["https://www.buymeacoffee.com/zernonia"],"categories":[],"sub_categories":[],"readme":"\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/zernonia/supadb\"\u003e\n    \u003cimg src=\"src/assets/logo.png\" alt=\"Logo\" width=\"80\" height=\"80\"\u003e\n  \u003c/a\u003e\n\n  \u003ch3 align=\"center\"\u003eSupaDB\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    Connect and play with \u003cstrong\u003e\u003ca href=\"https://supabase.io/\"\u003eSupabase\u003c/a\u003e\u003c/strong\u003e REST API / Graphql easily\n    \u003cbr /\u003e\n    Free • Open Source\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://supadb.dev/\"\u003eView Demo\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/zernonia/supadb/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/zernonia/supadb/issues\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n![Supabase Schema](public/og.png)\n\n## 🚀 Features\n\n- 🤩 Free\n- 🚀 Unlimited API Request\n- 🎨 Alowed to use on other project\n\n## 📇 About The Project\n\nThis is my **Supabase Bring the Func(🕺) Hackathon 2022** submission!\n\n**SupaDB** allows user that wanted to play with Supabase REST API/Grahql easily without having to manually seed the database.\n\n**SupaDB** also allows Frontend Developer that wanted to focus on design to easily fetch the data without worrying about CORS stuff.\n\n## Architecture\n\n### Insert/Update Data\n\n1. CRON Job by GitHub action\n2. Vercel Serverless to scrap data\n3. Upsert data into Supabase Database\n\n### Fetch Data\n\n1. Create custom secret for every user\n\n```sql\ncreate or replace function generate_secret ()\n  returns text\n  language plpgsql\n  as\n  $$\n    begin\n      return substr(md5(random()::text), 0, 25);\n    end;\n  $$\n```\n\n2. Wrap the secret in JWT token, set as Authorization Key in header\n\n3. RLS to verify secret token exist in request\n\n```sql\ncreate or replace function auth.verify() returns text as $$\n  select coalesce(\n    nullif(current_setting('request.jwt.claim.secret', true), ''),\n    nullif(current_setting('request.jwt.claims', true), '')::jsonb -\u003e\u003e 'secret'\n  )::text\n\n$$ language sql stable;\n```\n\n### Log Usage\n\nIn order to monitor the API usage, I created a temporary scripts to Insert Log data to a custom table\n\n1. Create Foreign Data Wrapper sing `file_fdw` [(GitHub discussion)](https://github.com/supabase/supabase/discussions/479)\n\n```sql\nCREATE EXTENSION file_fdw;\n\nCREATE SERVER logserver FOREIGN DATA WRAPPER file_fdw;\n\nCREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER logserver\nOPTIONS ( filename '/var/log/postgresql/postgresql.csv', format 'csv' );\n```\n\n2. Query data from `pglog` foreign table created in step 1.\n\n```sql\nselect * from\n  (select\n    concat(session_id, process_id, virtual_transaction_id) as id,\n    btrim(split_part(detail, ', ', 8), '$6= ''\"\"')::json -\u003e\u003e 'secret' as secret,\n    btrim(split_part(detail, ', ', 12), '$10= /''' ) as table,\n    log_time as created_at\n  from pglog where command_tag ~ 'SELECT' and message ~* 'execute 1'\n  ) as T\n  where T.table \u003c\u003e 'buckets'\n```\n\n3. Setup CRON job to insert above query to table\n\n```sql\nselect\n  cron.schedule(\n    'save-logfile', -- name of the cron job\n    '*/3 * * * *', -- every 3 minutes\n    $$\n    insert into history (id, secret, ref, created_at)\n      (/* step 2 */)\n    on conflict (id)\n    do nothing;\n    $$\n  );\n```\n\n4. Create view for easy monitor\n\n```sql\ncreate or replace view api_history\n  as select u.id as id, count(*) as count from\n    (select h.*, s.user_id from public.history h\n      left join public.secrets s on h.secret = s.secret\n      where h.secret is not null and h.created_at \u003e= now() - interval '1 day'\n    ) a\n  left join auth.users u on a.user_id = u.id\n  group by u.id\n```\n\n### 🔨 Built With\n\n- [Vue 3](https://vuejs.org/)\n- [Vite](https://vitejs.dev/)\n- [WindiCSS](https://windicss.org/)\n\n## 🌎 Local Development\n\n### Prerequisites\n\nYarn\n\n- ```sh\n  npm install --global yarn vercel\n  ```\n\n### Development\n\n1. Clone the repo\n   ```sh\n   git clone https://github.com/zernonia/supadb.git\n   ```\n2. Install NPM packages\n   ```sh\n   cd supadb\n   yarn install\n   ```\n3. Run local Vercel development instance\n   ```sh\n   vercel dev\n   ```\n\n## ➕ Contributing\n\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## 📜 License\n\nNot Associated with Supabase.\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n# 📧 Contact\n\nZernonia - [@zernonia](https://twitter.com/zernonia) - zernonia@gmail.com\n\nAlso, if you like my work, please buy me a coffee ☕😳\n\n\u003ca href=\"https://www.buymeacoffee.com/zernonia\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png\" alt=\"Logo\" \u003e\n  \u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzernonia%2Fsupadb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzernonia%2Fsupadb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzernonia%2Fsupadb/lists"}