çæAI âïž SQL ð° â¡ïž Supabase SQL Editor
ã¢ããã³ãã«ã¬ã³ããŒã®ãã¿æ¢ãããŠããããsupabase ã® SQL Editor ã AI æèŒãããŠããŠãé¢çœããã ã£ãã®ã§ãããã»ã»ã»ã»èšäºã«ããŠã¿ãŸãïŒ
åè¶ãªãã以äžã® advent ã«ã¬ã³ããŒã«ç»é²ãããŠããããŸããïŒ(supabase ãã£ãšçãäžããã»ã»ã»!ð)
Supabase SQL Editor: çæAIæèŒã® SQL ãšãã£ã¿
Supabase ããŸã詳ãããªãã§ãããããŸããŸèŠã€ãã以äžã®èšäºã«ãããšãä»å¹Žã®8æããã«ãããããšæ°ããæ©èœãåºãŠããã¿ããã§ãã
æ°æ©èœãåŒçšãããšïŒ
- Supabase AI in the SQL Editor: inline AI, always ready to help
- Schema Visualizer: â see all your table schemas visually.
- Role Management: â fine-grained access to table data
- Shared SQL Snippets: â share your snippets with the team
- Database Migration UI: â your database, with receipts
- Wrappers UI: â easily query foreign data
ãªãã§ãç¹ã«AIãå
¥ã£ãŠãã SQL Editor
ãæ°ã«ãªãïŒ
SQLãèããã®ããã©ããšããããããAIãSQLæžããŠã»ããã»ã»ã»
ããšã§è§ŠããŸãããSchema Visualizer
ããªããªã䟿å©ããã§ãã
ãšããããšã§ãSupabase ã®ãããžã§ã¯ããäœæããŠ(ç¡æ)ãAIæèŒã®SQL editor ãš Schema Visualizer ã®äœ¿ãåæã確èªããŠã¿ãŸããã
1. ã¢ã«ãŠã³ãäœæããããžã§ã¯ãäœæ
ãŸããã¢ã«ãŠã³ããªããã°ã¢ã«ãŠã³ãäœæããŸãããã¡ã¢ããç»é²ããã ãã§ç°¡åã«ã¢ã«ãŠã³ãäœããããšæããŸãã
ã¢ã«ãŠã³ãäœæ(ç¡æ)ããsupabase ã«ãã°ã€ã³ãããšã以äžã®ãããªç»é¢ãåºãŠããã®ã§ã
+ New Project
ãã¯ãªãã¯ããŠãããžã§ã¯ããäœæ(ç¡æ)ããŸãã
ãããžã§ã¯ãäœææãName ã¯é©åœãªãããžã§ã¯ãåãã€ããŸãã
ããã§ããã¹ã¯ãŒããèšå®ããŸãããåŸã»ã© postgresql ãžã®æ¥ç¶ã§å¿
èŠãªã®ã§ããã¹ã¯ãŒãã¯ã¡ãããšèŠããŠãããŸãã
Region ã¯ããããæ¥æ¬ãããã§ãããã
以äžã§ããããžã§ã¯ãäœæãçµãããsupabase ã® postgresql ã® DB ã䜿ããããã«ãªããŸãã
è©Šãã«ãsupabase ã§ãã¹ããããŠãã postgresql ã«ããŒã«ã«PCã®ã¿ãŒããã«ããæ¥ç¶ããŠã¿ãŸãã
ãã°ã€ã³ã«å¿
èŠãªã³ãã³ãã¯äŸ¿å©ãªããšã«ãsupabase ã®ç®¡çç»é¢ããã³ããã§ããŸãã
â(æ¯è»)ããŒã¯ãã¯ãªãã¯ããŠãå·Šã®ãã€ã³ãã Database
ãã¯ãªãã¯ãããšä»¥äžã®ç»é¢ãéããConnection string
ã®ãšããã« postgresql ã«ãã°ã€ã³ããããã® psql ã³ãã³ããçšæãããŠããŸãããããã³ããŒã
Connection string ã«ããã°ã©ãã³ã°å¥ã®æ¥ç¶æ
å ±ããããŸããããšãããã PSQL ã䜿ããŸã
ããŒã«ã«ã®ã¿ãŒããã«ã«ãpsql ãããæ¹ã¯ãã³ããŒããã³ãã³ãããã®ãŸãŸå®è¡ã§ããŸããã
èªåã®ç«¯æ«ã«ã¯ postgresql ã€ã³ã¹ããŒã«ããŠããªãã®ã§ãdocker ã³ã³ããã§å®è¡ããŸãã
ãã¹ã¯ãŒãèãããã®ã§ãsupabase ãããžã§ã¯ãäœææã«èšå®ãããã¹ã¯ãŒããå
¥åããŸãã
⯠docker run \
-it \
--name psql \
--rm \
postgres:16.1 psql -h xxxxxxxxxxxxxxxxxxx.supabase.co -p 5432 -d postgres -U postgres
Password for user postgres:
docker ã³ãã³ãã®ã¹ã€ããã¯ãç¹å¥ãªãã®ã¯ãªãã§ããã
ã³ã³ããã®åŒæ°ã«ã¯ãsupabase ã®ç®¡çç»é¢ããã³ããŒããã³ãã³ãã䜿ããŸãã(ãŠãŒã¶ãŒåããDBã®æå®ã¯å€æŽäžèŠ)
ãã¹ã¯ãŒããå ¥åããŠãpsql ã®ããã³ãããåºãŠããããçéã¯æåã§ãã
postgres=>
2. ãã³ããã¡ã€ã«ãã supabase ã® DB ã«ãµã³ãã«ã®ããŒãã«ãäœæãã
SQL Editor ã§ãããã§XXãªã¬ã³ãŒããæ€çŽ¢ããŠïŒãã¿ãããªæ瀺ãAIã«åºããããã§ããã
ããããã®ããŒãã«ãšã¬ã³ãŒããç¡ããšå§ããããªãã®ã§ããµã³ãã«ããŒã¿ãå¿
èŠã§ããã
ãããŠãpostgresql ã ãšã¬ã³ã¿ã«DVDãããŒãã«ãããµã³ãã«DBã®ãã³ããã¡ã€ã«ããããããããŠã³ããŒãã§ããèšæ¶ãã»ã»ã»ïŒæpostgresql調ã¹ããšãã®èšæ¶)
ããã£ãŠã¿ããšä»¥äžã®ãµã€ãã§ãpostgresql ã®ãµã³ãã«DBã®ãã³ããããŠã³ããŒãã§ããŸããã
Download DVD Rental Sample Database
ã®ãªã³ã¯ã¯ãªãã¯ãããããŠã³ããŒãã§ããŸãã
ããŠã³ããŒããããã¡ã€ã«ã zip ããã tar ãã¡ã€ã«ãªã®ã§ããŸãã¯è§£å
unzip dvdrental.zip
次ã«ãpg_restore
ã䜿ã£ãŠãsupabase ã® DB ã«ãã³ããã¡ã€ã«ãèªã¿èŸŒãŸããŸãã
pg_restore
㯠postgres ã® docker ã€ã¡ãŒãžã«å«ãŸããŠããã®ã§ãããã䜿ããŸãã
docker run \
-it \
--workdir /psql \
-v $(pwd):/psql \
--name psql \
--rm \
postgres:16.1 pg_restore -h db.xxxxxxxxxxxxxxxx.supabase.co -p 5432 -d postgres -U postgres dvdrental.tar
docker ã³ãã³ãã®ã¹ã€ããã¯ãããŠã³ããŒããããã³ããã¡ã€ã«ãã³ã³ããã«ãã€ã³ãããŠã³ãããŠããŸããâ --v $(pwd):/psql
èå¿ã® ps_restore ã³ãã³ãã®åŒæ°ã¯åè¿°ã®çé確èªæã«äœ¿ã£ã psql ã³ãã³ãã®åŒæ°ãšã»ãŒåãã§ãããæ¹ããŠç¢ºèªãããšãããã
-
-h
: supabase ã® postgresql ãµãŒããŒã®ãã¹ãå -
-p
: ããŒãçªå·ãããã©ã«ããæå® -
-d
: DBãæå®(ã¯ãããããã postgres ã® db ãæå®) -
-U
: ãŠãŒã¶ãŒåãpostgres
åºå® - åŒæ°ã¯ãããŠã³ããŒããã解åãããã³ããã¡ã€ã«
dvdrental.tar
ãã®ã³ãã³ãã§ãã³ããã¡ã€ã«ãèªã¿èŸŒãŸããã®ã¯æ°ç§ãããããšæããŸãã(ãããã¯ãŒã¯ç¶æ³ã«ãã£ãŠã¯ãã£ãšã»ã»ïŒ)
çµãã£ãããpsql 㧠supabase äžã® postgresql ã«æ¥ç¶ããŠç¢ºèªããŠã¿ãŸãã
æ¥ç¶ã®ã³ãã³ã:
⯠docker run \
-it \
--name psql \
--rm \
postgres:16.1 psql -h xxxxxxxxxxxxxxxxxxx.supabase.co -p 5432 -d postgres -U postgres
æ¥ç¶åŸã以äžã®ã³ãã³ããå®è¡
postgres ã®ååãã€ãã db ããããŸãã
postgres=> \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+---------+---------+------------+-----------+-----------------------------
postgres | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =Tc/postgres +
| | | | | | | | postgres=CTc/postgres +
| | | | | | | | dashboard_user=CTc/postgres
template0 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(3 rows)
次ã®ã³ãã³ãã§ãã® db ã«æ¥ç¶ããŸãã
postgres=> \c postgres
postgresql ã«å
¥ãããã³ããã¡ã€ã«ã« actor
ããŒãã«ãå«ãŸããŠããã®ã§ãè©Šãã«ããã select ããŠã¿ãŸã
dvdrental=> select * from actor;
actor_id | first_name | last_name | last_update
----------+-------------+--------------+------------------------
1 | Penelope | Guiness | 2013-05-26 14:47:57.62
2 | Nick | Wahlberg | 2013-05-26 14:47:57.62
3 | Ed | Chase | 2013-05-26 14:47:57.62
4 | Jennifer | Davis | 2013-05-26 14:47:57.62
5 | Johnny | Lollobrigida | 2013-05-26 14:47:57.62
ïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœ
çç¥
ïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœïœ
ãã³ããã¡ã€ã«ã postgresql ã«å
¥ã£ãŠããããšã確èªã§ããŸããã
actor ããŒãã«ä»¥å€ã«ãæ§ã
ãªããŒãã«ãå
¥ã£ãŠããŸãã
ãã®ç¶æ ã§æŽã«ã Schema Visualizer ã§ã©ããªããŒãã«ãã©ããªãªã¬ãŒã·ã§ã³ã§ååšããŠããã®ã確èªããããšãã§ããŸãã(ã€ãŸã ER å³)
ããŒã¿ãæå
¥ããã ãã§ãåæã«ERå³ãŸã§çæããŠããããªããŠäŸ¿å©ã§ããïŒ
å
šäœåãããããããŸãã
3. SQL Editor ã䜿ãå§ããåã«å°ãèšå®ãå¿ èŠ
SQL Editor ã§æåãã AI ã䜿ããã®ã§ããããããžã§ã¯ãã«å«ãŸããããŒãã«ãAIã®ã³ã³ããã¹ãã«å ¥ããããã«ãèšå®ãå¿ èŠã§ãããããããªããšãAIã«æ瀺ãåºããŠããæ¢åã®ãããžã§ã¯ãã®ããŒãã«ãèæ ®ããªããžã§ããªãã¯ãªSQLããçæããŠãããŸããã
ãã®èšå®ã«é¢ããŠãããã¥ã¡ã³ãã§èª¬æãèŠã€ããããªãã£ãã§ãããããããšã¯ç°¡åã§ã以äžã®ã¹ã¯ã·ã§ã®ããã«ã SQL Editor ã®ç»é¢å³äžã«ãããâæ¯è»ããŒã¯ãã¯ãªãã¯ããŠã Include anonymous database metadata in AI queries
ãæå¹ã«ããŸãã
ããããããšã§ãããŒãã«åãã«ã©ã ãã«ã©ã ã®åã®æ
å ±ãªã©ããAI ã« metadata ãšããŠéä¿¡ãããããã«ãªããŸãã
anonymouse
(å¿å) ãšæžããŠãããšãããããããããã«ãããŒãã«åãšãã®ã¡ã¿ããŒã¿ã¯AIã«éãããŸãããã¬ã³ãŒããšãã¯éãããªããããªã®ã§ãäžå¿ã»ã³ã·ãã£ããªæ
å ±ãå€ã«æŒãåºããªãããã«é
æ
®ãããŠããããã§ãã(ããŒãã«åãã«ã©ã åã«ã¬ãããªå人æ
å ±ãç§å¯ã®æ
å ±ãå«ãŸããŠããããããŸãã§ããããããªããšã¯ããŸãç¡ãã§ãããã)
4. AI ã«äŸé Œã㊠SQL ãçæããŠãããããšãããã倱æïŒ
ã ãã§ããïŒå®è¡ã§ããŸããã§ããïŒ
å çš postgresql ã«å ¥ãããã³ããã¡ã€ã«ã®ãµã³ãã«DBã«å«ãŸããããŒãã«ãã«ã©ã ã®ç·æ°ãå€ãããã£ãœãã§ãã
æ®å¿µãªãã顧客ã®ãªã¹ãã¯æã«å ¥ãã(ãããŒããŒã¿ããšã§ã)ã
5. AI ã«ããŒãã«ãçšæããŠãããã
ããŒãã«ãå€ããããšã ããªããããèªåã§æ°åã®ããŒãã«ãäœã£ãŠãã£ãŠã¿ãŸãã
æ°ãããããžã§ã¯ããäœãçŽããŠããŸã£ãããªç¶æ ããããçŽããŸããã
ãããŠãã£ãããªã®ã§ãæ°ããããŒãã«ãAIã«çšæããŠããããŸãã
äžèšã®ããã« CREATE TABLE æãçæããŠãããããããã®ãŸãŸ RUN(å®è¡) ãããšãããŒãã«ãäœæãããŸããã
ãã®çµæã¯ãSchema Visualizer
ã® ER å³ã§ã確èªã§ããŸããã
ã«ã©ã ã®åãé©åã§ãªãã£ããã絶察ã«ããŒãã«è¶³ããŠãªãã£ããããŸããããªããµãæ§ããç¶ããŸãã
6. AI ã«ã¬ã³ãŒããå ¥ããŠãããã
orders ããŒãã«ã«é©åœã«ãããŒã¬ã³ãŒããå ¥ããŠã¿ããã§ãã
ãã ãorders ããŒãã«ã¯ãstaff ããŒãã«ãšãproduct ããŒãã«ã®ã«ã©ã ãåç §ããŠããã®ã§ãåç §å ã®ã¬ã³ãŒããç¡ããšããããšã§ãå€éšããŒå¶çŽã®ãšã©ãŒãèµ·ããŠããŸããŸããã
æ°ãåãçŽããŠãåç §å ã®ãããŒã¬ã³ãŒãããå ã«äœæããŸãã
ããã³ãããèŠåããŠããŸã£ãã®ã§ããšãã£ã¿ãŒãšãªã¢ã«ããã³ããã貌ãä»ã
ããã³ããå®è¡ãããšãinsert æã€ãã£ãŠãããŸãã
ããã£ãœããã¶ã®ååã®ã¬ã³ãŒããäœã INSERT æãã§ããŸããïŒ
å®è¡ããŠããšã©ãŒãªããINSERT ã§ããŸããã
ç¶ããŠã¹ã¿ããããŒãã«ã® INSERT æäœæãäŸé ŒããŠã¿ãŸãã
ããã³ãããèŠåããŠããŸã£ãã®ã§ããšãã£ã¿ãŒãšãªã¢ã«ããã³ããã貌ãä»ã
7. ãããã SQL ãšãã£ã¿ã«å¿ èŠãªããŒã¿ãã¯ãšãªããŠããããŸãïŒ
SQL ãçæ
çµæ
ãããèªç¶èšèªã§ DB ã®ã¬ã³ãŒãæ€çŽ¢ãã§ããŸããã
ãããŸã§é£ããã¯ãšãªã§ã¯ç¡ããã®ã®ãSQLæ £ããŠããªã人ã¯ãã®ã¬ãã«ã§ãå°ãé ãæ±ããŠããŸããããããŸãããããããèªç¶èšèªã§äŸé ŒããŠãã SQL çæããŠãããã䟿å©ããã§ããïŒ
å¿ èŠã«å¿ããŠãæŽã«ã¯ãšãªãæŽæ°ããããšãå¯èœã§ãã
ãŸãšã
ãµã¯ããšäœã£ããã£ã3ã€ã®ããŒãã«ãæã€DBã§ãèªç¶èšèªã䜿ã£ãæ€çŽ¢ãç°¡åã«ã§ãããã§é¢çœããšæããŸããã
ãã ãå®éã¯ããã£ãšè€éãªã«ã©ã ãæã€ãã£ãšå€æ°ã®ããŒãã«ã§æ§æãããDBãæ¥åã§ã¯äœ¿ãããšã«ãªãã®ã§ãæåã®ã¬ã³ã¿ã«DVDã®DBã§ãã®AIã䜿ããªãã£ãã®ãæ®å¿µã§ããã»ã»ã»(ã«ã©ã ã®æ å ±ãããŒãã«ã®æ å ±ãªã©ã® metadata ãå€ããããšAIããšã©ãŒãèµ·ãã)
Discussion