Class: DbSchema::Reader::Postgres::Table
- Inherits:
-
Object
- Object
- DbSchema::Reader::Postgres::Table
- Defined in:
- lib/db_schema/reader/postgres/table.rb
Constant Summary collapse
- SERIAL_TYPES =
{ smallint: :smallserial, integer: :serial, bigint: :bigserial }.freeze
- DEFAULT_VALUE =
/\A( ('(?<date>\d{4}-\d{2}-\d{2})'::date) | ('(?<time>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}([+-]\d{2})?)'::timestamp) | ('(?<string>.*)') | (?<float>\d+\.\d+) | (?<integer>\d+) | (?<boolean>true|false) )/x- FKEY_ACTIONS =
{ a: :no_action, r: :restrict, c: :cascade, n: :set_null, d: :set_default }.freeze
Instance Attribute Summary collapse
-
#checks_data ⇒ Object
readonly
Returns the value of attribute checks_data.
-
#fields_data ⇒ Object
readonly
Returns the value of attribute fields_data.
-
#fkeys_data ⇒ Object
readonly
Returns the value of attribute fkeys_data.
-
#indexes_data ⇒ Object
readonly
Returns the value of attribute indexes_data.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #checks ⇒ Object
- #definition ⇒ Object
- #fields ⇒ Object
- #foreign_keys ⇒ Object
- #indexes ⇒ Object
-
#initialize(table_name, fields_data, indexes_data, checks_data, fkeys_data) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(table_name, fields_data, indexes_data, checks_data, fkeys_data) ⇒ Table
Returns a new instance of Table.
35 36 37 38 39 40 41 |
# File 'lib/db_schema/reader/postgres/table.rb', line 35 def initialize(table_name, fields_data, indexes_data, checks_data, fkeys_data) @table_name = table_name @fields_data = fields_data @indexes_data = indexes_data @checks_data = checks_data @fkeys_data = fkeys_data end |
Instance Attribute Details
#checks_data ⇒ Object (readonly)
Returns the value of attribute checks_data.
33 34 35 |
# File 'lib/db_schema/reader/postgres/table.rb', line 33 def checks_data @checks_data end |
#fields_data ⇒ Object (readonly)
Returns the value of attribute fields_data.
33 34 35 |
# File 'lib/db_schema/reader/postgres/table.rb', line 33 def fields_data @fields_data end |
#fkeys_data ⇒ Object (readonly)
Returns the value of attribute fkeys_data.
33 34 35 |
# File 'lib/db_schema/reader/postgres/table.rb', line 33 def fkeys_data @fkeys_data end |
#indexes_data ⇒ Object (readonly)
Returns the value of attribute indexes_data.
33 34 35 |
# File 'lib/db_schema/reader/postgres/table.rb', line 33 def indexes_data @indexes_data end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
33 34 35 |
# File 'lib/db_schema/reader/postgres/table.rb', line 33 def table_name @table_name end |
Instance Method Details
#checks ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/db_schema/reader/postgres/table.rb', line 65 def checks checks_data.map do |check_data| Definitions::CheckConstraint.new( name: check_data[:name].to_sym, condition: check_data[:condition] ) end end |
#definition ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/db_schema/reader/postgres/table.rb', line 43 def definition Definitions::Table.new( table_name, fields: fields, indexes: indexes, checks: checks, foreign_keys: foreign_keys ) end |
#fields ⇒ Object
53 54 55 56 57 |
# File 'lib/db_schema/reader/postgres/table.rb', line 53 def fields fields_data.map do |field_data| build_field(field_data) end end |
#foreign_keys ⇒ Object
74 75 76 77 78 |
# File 'lib/db_schema/reader/postgres/table.rb', line 74 def foreign_keys fkeys_data.map do |foreign_key_data| build_foreign_key(foreign_key_data) end end |
#indexes ⇒ Object
59 60 61 62 63 |
# File 'lib/db_schema/reader/postgres/table.rb', line 59 def indexes indexes_data.map do |index_data| build_index(index_data) end.sort_by(&:name) end |