SidePanelEditor.constants.ts 3.2 KB

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