Skip to content

Commit

Permalink
3. 모델 타입 불러오기
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed May 21, 2024
1 parent 25fa9f4 commit c40f123
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ assets/langs/ios/

# types
*.d.ts

src/types/supabase.ts
6 changes: 3 additions & 3 deletions app/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default function Details(): JSX.Element {
<Button
onPress={async () => {
try {
const {error} = await supabase
.from('todos')
.insert({id: 1, todo: 'Buy Milk'});
const {error} = await supabase.from('User').insert({
email: '[email protected]',
});

console.log('error', error);

Check warning on line 35 in app/details.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
} catch (err) {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lint:all": "bun lint && bun lint:i18n",
"build:web": "expo export --platform web",
"test": "jest --runInBand",
"generate:supabase": "supabase gen types typescript --project-id \"whtonfqidbwxlsdsamba\" --schema public > src/types/supabase.ts",
"migrate:dev": "dotenv -e .env -- prisma migrate dev",
"migrate:local": "dotenv -e .env -- prisma migrate local",
"migrate:deploy": "dotenv -e .env.production -- prisma migrate deploy"
Expand Down Expand Up @@ -101,6 +102,7 @@
"prettier": "^3.2.5",
"prisma": "^5.14.0",
"react-test-renderer": "18.2.0",
"supabase": "^1.167.4",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "~5.3.3"
Expand Down
184 changes: 184 additions & 0 deletions src/types/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
export type Json =
| string
| number
| boolean
| null
| { [key: string]: Json | undefined }
| Json[]

export type Database = {
public: {
Tables: {
_prisma_migrations: {
Row: {
applied_steps_count: number
checksum: string
finished_at: string | null
id: string
logs: string | null
migration_name: string
rolled_back_at: string | null
started_at: string
}
Insert: {
applied_steps_count?: number
checksum: string
finished_at?: string | null
id: string
logs?: string | null
migration_name: string
rolled_back_at?: string | null
started_at?: string
}
Update: {
applied_steps_count?: number
checksum?: string
finished_at?: string | null
id?: string
logs?: string | null
migration_name?: string
rolled_back_at?: string | null
started_at?: string
}
Relationships: []
}
User: {
Row: {
avatar_url: string | null
created_at: string | null
description: string | null
email: string
full_name: string | null
gender: Database["public"]["Enums"]["Gender"] | null
id: string
name: string | null
phone: string | null
provider: Database["public"]["Enums"]["AuthType"]
updated_at: string | null
}
Insert: {
avatar_url?: string | null
created_at?: string | null
description?: string | null
email: string
full_name?: string | null
gender?: Database["public"]["Enums"]["Gender"] | null
id?: string
name?: string | null
phone?: string | null
provider?: Database["public"]["Enums"]["AuthType"]
updated_at?: string | null
}
Update: {
avatar_url?: string | null
created_at?: string | null
description?: string | null
email?: string
full_name?: string | null
gender?: Database["public"]["Enums"]["Gender"] | null
id?: string
name?: string | null
phone?: string | null
provider?: Database["public"]["Enums"]["AuthType"]
updated_at?: string | null
}
Relationships: []
}
}
Views: {
[_ in never]: never
}
Functions: {
[_ in never]: never
}
Enums: {
AuthType: "email" | "google"
Gender: "male" | "female" | "intersex"
}
CompositeTypes: {
[_ in never]: never
}
}
}

type PublicSchema = Database[Extract<keyof Database, "public">]

export type Tables<
PublicTableNameOrOptions extends
| keyof (PublicSchema["Tables"] & PublicSchema["Views"])
| { schema: keyof Database },
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
Database[PublicTableNameOrOptions["schema"]]["Views"])
: never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
? (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends {
Row: infer R
}
? R
: never
: PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] &
PublicSchema["Views"])
? (PublicSchema["Tables"] &
PublicSchema["Views"])[PublicTableNameOrOptions] extends {
Row: infer R
}
? R
: never
: never

export type TablesInsert<
PublicTableNameOrOptions extends
| keyof PublicSchema["Tables"]
| { schema: keyof Database },
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
: never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
Insert: infer I
}
? I
: never
: PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
Insert: infer I
}
? I
: never
: never

export type TablesUpdate<
PublicTableNameOrOptions extends
| keyof PublicSchema["Tables"]
| { schema: keyof Database },
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
: never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
Update: infer U
}
? U
: never
: PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
Update: infer U
}
? U
: never
: never

export type Enums<
PublicEnumNameOrOptions extends
| keyof PublicSchema["Enums"]
| { schema: keyof Database },
EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database }
? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"]
: never = never,
> = PublicEnumNameOrOptions extends { schema: keyof Database }
? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName]
: PublicEnumNameOrOptions extends keyof PublicSchema["Enums"]
? PublicSchema["Enums"][PublicEnumNameOrOptions]
: never
3 changes: 2 additions & 1 deletion supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import 'react-native-url-polyfill/auto';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {createClient} from '@supabase/supabase-js';

import type {Database} from './src/types/supabase';
import {supabaseAnonKey, supabaseUrl} from './config';

export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey, {
auth: {
storage: AsyncStorage,
autoRefreshToken: true,
Expand Down

0 comments on commit c40f123

Please sign in to comment.