supabase CLI를 이용해 간단하게 데이터베이스의 전체 타입을 생성해서 사용할 수 있다!
https://supabase.com/docs/guides/local-development
Local Development & CLI | Supabase Docs
Learn how to develop locally and use the Supabase CLI
supabase.com
설치 및 세팅
기본적으로 supabase를 js에서 사용하기 위한 세팅은 되어있다고 가정!
npm install supabase --save-dev
package.json에서 gen 명령어 지정해두기
"gen": "supabase gen types --lang=typescript --project-id \"{supabase에서 project id 확인해 주가하기}\" --schema public > src/lib/type/database.types.ts"
터미널에서 yarn gen 실행했을 때, accessToken 오류가나면 supabase login 명령어를 통해 인증
타입 사용하기
이제 .fom('table name').select() 등에서 타입을 추론할 수 있다
아래와같이 타입을 선언해두면 테이블 구조가 바뀌었을때도 편하게 수정할 수 있다
export type Schedule = Database['public']['Tables']['schedule']['Row'];
'supabase' 카테고리의 다른 글
[supabase] 세팅하기 (5) | 2024.10.08 |
---|---|
[Supabase] supabase.store insert 오류 해결 (0) | 2024.08.30 |