Module: ViewData::PG::Controls::Table::AllDataTypes

Defined in:
lib/view_data/pg/controls/table/all_data_types.rb

Class Method Summary collapse

Class Method Details

.create(drop: nil) ⇒ Object



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
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/view_data/pg/controls/table/all_data_types.rb', line 6

def self.create(drop: nil)
  session = Session.build

  if drop
    session.execute("DROP TABLE IF EXISTS #{name}")
    session.execute("DROP TYPE IF EXISTS some_enum_type")
  end

  begin
    session.execute(<<~SQL)
      CREATE TYPE some_enum_type AS ENUM (
        '#{Enum.example}',
        '#{Enum.alternate}'
        )
    SQL
  rescue ::PG::DuplicateObject
  end

  session.execute(<<~SQL)
    CREATE TABLE #{name} (
      id uuid PRIMARY KEY,

      -- Numbers
      some_smallint smallint,
      some_integer integer,
      some_bigint bigint,
      some_decimal_3_1 decimal(4, 1),
      some_numeric_3_1 numeric(4, 1),
      some_real real,
      some_double_precision double precision,
      some_smallserial smallserial,
      some_serial serial,
      some_bigserial bigserial,

      -- Money
      some_money money,

      -- Character
      some_varchar_3 character varying(3),
      some_char_3 character(3),
      some_text text,

      -- Binary
      some_bytea bytea,

      -- Date/Time
      some_timestamp_3 timestamp(3) without time zone,
      some_timestamp_3_with_tz timestamp(3) with time zone,
      some_date date,
      some_time_3 time(3) without time zone,
      some_time_3_with_tz time(3) with time zone,
      some_interval_year interval YEAR,
      some_interval_second_3 interval SECOND(3),

      -- Boolean
      some_boolean bool,

      -- Enum
      some_enum some_enum_type,

      -- UUID
      some_uuid uuid,

      -- JSON
      some_json_text json,
      some_json_binary jsonb
    )
  SQL

  session.close
end

.nameObject



78
79
80
# File 'lib/view_data/pg/controls/table/all_data_types.rb', line 78

def self.name
  'all_data_types'
end