Class: HQ::Structure::Inserts
- Inherits:
-
Object
- Object
- HQ::Structure::Inserts
- Includes:
- TSort
- Defined in:
- lib/hq/structure/inserts.rb
Instance Attribute Summary collapse
-
#connection_pool ⇒ Object
readonly
Returns the value of attribute connection_pool.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(connection_pool:, tables:) ⇒ Inserts
constructor
A new instance of Inserts.
Constructor Details
#initialize(connection_pool:, tables:) ⇒ Inserts
Returns a new instance of Inserts.
11 12 13 14 15 16 17 18 19 |
# File 'lib/hq/structure/inserts.rb', line 11 def initialize(connection_pool:, tables:) @connection_pool = connection_pool @dependencies = {} @tables = Set.new tables.select { |table_name| connection_pool.with_connection { |c| c.table_exists?(table_name) } }.each do |t| build_dependencies!(t) end end |
Instance Attribute Details
#connection_pool ⇒ Object (readonly)
Returns the value of attribute connection_pool.
9 10 11 |
# File 'lib/hq/structure/inserts.rb', line 9 def connection_pool @connection_pool end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
9 10 11 |
# File 'lib/hq/structure/inserts.rb', line 9 def dependencies @dependencies end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
9 10 11 |
# File 'lib/hq/structure/inserts.rb', line 9 def tables @tables end |
Instance Method Details
#build ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hq/structure/inserts.rb', line 21 def build tsort.lazy.map do |table_name| sql = build_sql(table_name) sequence = sequence_sql(table_name) if sql [ *sql, *sequence ].join("\n").presence end.reject(&:nil?) end |