-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsupabase.extended.ts
63 lines (56 loc) · 1.5 KB
/
supabase.extended.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Database as PostgresSchema } from './supabase';
type PostgresTables = PostgresSchema['public']['Tables'];
// THIS IS THE ONLY THING YOU EDIT
// <START>
type TableExtensions = {
/**
my_existing_table_name: {
my_json_column_override: {
tel: string;
name?: string;
preset_id?: number;
};
};
**/
};
// <END>
// ☝️ this is the only thing you edit
type TakeDefinitionFromSecond<T extends object, P extends object> = Omit<
T,
keyof P
> &
P;
type NewTables = {
[k in keyof PostgresTables]: {
Row: k extends keyof TableExtensions
? TakeDefinitionFromSecond<
PostgresTables[k]['Row'],
TableExtensions[k]
>
: PostgresTables[k]['Row'];
Insert: k extends keyof TableExtensions
? TakeDefinitionFromSecond<
PostgresTables[k]['Insert'],
TableExtensions[k]
>
: PostgresTables[k]['Insert'];
Update: k extends keyof TableExtensions
? Partial<
TakeDefinitionFromSecond<
PostgresTables[k]['Update'],
TableExtensions[k]
>
>
: PostgresTables[k]['Update'];
};
};
export type Database = {
public: Omit<PostgresSchema['public'], 'Tables'> & {
Tables: NewTables;
};
};
export type TableName = keyof Database['public']['Tables'];
export type TableRow<T extends TableName> =
Database['public']['Tables'][T]['Row'];
export type TableView<View extends keyof Database['public']['Views']> =
Database['public']['Views'][View]['Row'];