Class: PgGraph::Type::Table

Inherits:
SchemaObject show all
Includes:
TableObject
Defined in:
lib/pg_graph/type/type.rb

Overview

A table. Note that a table doesn’t have child objects. Instead it has a type property that has the record type as child

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TableObject

#record_type, #table

Methods inherited from SchemaObject

#schema_identifier

Methods inherited from Node

#dump, #guid, #identifier, #inspect, #inspect_inner, #schema_identifier

Constructor Details

#initialize(schema, name, mm_table: false, nm_table: false, depending_materialized_views: []) ⇒ Table

Returns a new instance of Table.



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/pg_graph/type/type.rb', line 179

def initialize(
    schema, name,
    mm_table: false, nm_table: false, depending_materialized_views: [])
  PgGraph.inflector.plural?(name) or raise Error, "Table names should be plural: #{schema.name}.#{name}"
  super(schema, name)
  @path = "#{schema.name}.#{name}"
  @mm_table = mm_table || nm_table
  @nm_table = nm_table
  @depending_tables = []
  @depending_materialized_views = depending_materialized_views
end

Instance Attribute Details

#depending_materialized_viewsObject (readonly)

This is a hack since graph_db doesn’t model views. It is needed because PgGraph::Data needs to know which materialized views to refresh after data has been loaded



177
178
179
# File 'lib/pg_graph/type/type.rb', line 177

def depending_materialized_views
  @depending_materialized_views
end

#depending_tablesObject (readonly)

Array of tables in the transitive closure of table dependencies. It is initialized by Database#read_meta



172
173
174
# File 'lib/pg_graph/type/type.rb', line 172

def depending_tables
  @depending_tables
end

#pathObject (readonly)

Qualified name of table (ie. schema.table). FIXME: We already have Node#path???



147
148
149
# File 'lib/pg_graph/type/type.rb', line 147

def path
  @path
end

#typeObject Also known as: table_type

Table type. Initially nil. Initialized by RecordType.new



150
151
152
# File 'lib/pg_graph/type/type.rb', line 150

def type
  @type
end

Instance Method Details

#mm_table?Boolean

Returns:

  • (Boolean)


167
# File 'lib/pg_graph/type/type.rb', line 167

def mm_table?() @mm_table end

#nm_table?Boolean

Returns:

  • (Boolean)


168
# File 'lib/pg_graph/type/type.rb', line 168

def nm_table?() @nm_table end

#root_tableObject

Recursive parent table if table is a derived table and otherwise nil



162
# File 'lib/pg_graph/type/type.rb', line 162

def root_table = record_type.root_record&.table

#sub_table?Boolean

True if table is a derived table. TODO: Use sub_table etc.

Returns:

  • (Boolean)


156
# File 'lib/pg_graph/type/type.rb', line 156

def sub_table?() !super_table.nil? end

#super_tableObject

Parent table if this table is a derived table and otherwise nil



159
# File 'lib/pg_graph/type/type.rb', line 159

def super_table = record_type.super_record&.table

#super_table?Boolean

True if table is a parent table. Initialized by #read

Returns:

  • (Boolean)


165
# File 'lib/pg_graph/type/type.rb', line 165

def super_table?() record_type.sub_record? end