SidePanelEditor.constants.ts141 lines · main
1import { concat, sortBy } from 'lodash'
2
3import type { PostgresDataTypeOption } from './SidePanelEditor.types'
4
5export const NUMERICAL_TYPES = [
6 'int2',
7 'int4',
8 'int8',
9 'float4',
10 'float8',
11 'numeric',
12 'double precision',
13]
14export const JSON_TYPES = ['json', 'jsonb']
15export const TEXT_TYPES = ['text', 'varchar']
16
17export const TIMESTAMP_TYPES = ['timestamp', 'timestamptz']
18export const DATE_TYPES = ['date']
19export const TIME_TYPES = ['time', 'timetz']
20export const DATETIME_TYPES = concat(TIMESTAMP_TYPES, DATE_TYPES, TIME_TYPES)
21
22export const OTHER_DATA_TYPES = ['uuid', 'bool', 'vector', 'bytea']
23export const POSTGRES_DATA_TYPES = sortBy(
24 concat(NUMERICAL_TYPES, JSON_TYPES, TEXT_TYPES, DATETIME_TYPES, OTHER_DATA_TYPES)
25)
26
27export const RECOMMENDED_ALTERNATIVE_DATA_TYPE: {
28 [key: string]: { alternative: string; reference: string }
29} = {
30 varchar: {
31 alternative: 'text',
32 reference:
33 "https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_varchar.28n.29_by_default",
34 },
35 json: {
36 alternative: 'jsonb',
37 reference: 'https://www.postgresql.org/docs/current/datatype-json.html',
38 },
39 timetz: {
40 alternative: 'timestamptz',
41 reference: "https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_timetz",
42 },
43 timestamp: {
44 alternative: 'timestamptz',
45 reference:
46 "https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_timestamp_.28without_time_zone.29",
47 },
48}
49
50export const POSTGRES_DATA_TYPE_OPTIONS: PostgresDataTypeOption[] = [
51 {
52 name: 'int2',
53 description: 'Signed two-byte integer',
54 type: 'number',
55 },
56 {
57 name: 'int4',
58 description: 'Signed four-byte integer',
59 type: 'number',
60 },
61 {
62 name: 'int8',
63 description: 'Signed eight-byte integer',
64 type: 'number',
65 },
66 {
67 name: 'float4',
68 description: 'Single precision floating-point number (4 bytes)',
69 type: 'number',
70 },
71 {
72 name: 'float8',
73 description: 'Double precision floating-point number (8 bytes)',
74 type: 'number',
75 },
76 {
77 name: 'numeric',
78 description: 'Exact numeric of selectable precision',
79 type: 'number',
80 },
81 {
82 name: 'json',
83 description: 'Textual JSON data',
84 type: 'json',
85 },
86 {
87 name: 'jsonb',
88 description: 'Binary JSON data, decomposed',
89 type: 'json',
90 },
91 {
92 name: 'text',
93 description: 'Variable-length character string',
94 type: 'text',
95 },
96 {
97 name: 'varchar',
98 description: 'Variable-length character string',
99 type: 'text',
100 },
101 {
102 name: 'uuid',
103 description: 'Universally unique identifier',
104 type: 'text',
105 },
106 {
107 name: 'date',
108 description: 'Calendar date (year, month, day)',
109 type: 'time',
110 },
111 {
112 name: 'time',
113 description: 'Time of day (no time zone)',
114 type: 'time',
115 },
116 {
117 name: 'timetz',
118 description: 'Time of day, including time zone',
119 type: 'time',
120 },
121 {
122 name: 'timestamp',
123 description: 'Date and time (no time zone)',
124 type: 'time',
125 },
126 {
127 name: 'timestamptz',
128 description: 'Date and time, including time zone',
129 type: 'time',
130 },
131 {
132 name: 'bool',
133 description: 'Logical boolean (true/false)',
134 type: 'bool',
135 },
136 {
137 name: 'bytea',
138 description: 'Variable-length binary string',
139 type: 'others',
140 },
141]