Sha256: 5e1a7d6e8b0cf8431d5567cdca3a81068e85de20bc6c542e3df06b41e1abd0a0
Contents?: true
Size: 1.14 KB
Versions: 7
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true module TableSaw module DependencyGraph class DumpTable attr_reader :manifest, :name, :partial, :ids def initialize(manifest:, name:, partial: true) @manifest = manifest @name = name @partial = partial @ids = Set.new end def copy_statement if partial format 'select * from %{name} where %{clause}', name: name, clause: TableSaw::Queries::SerializeSqlInClause.new(name, primary_key, ids.to_a).call else "select * from #{name}" end end def fetch_associations(directive) directive.ids = directive.ids - ids.to_a ids.merge(directive.ids) fetch_belongs_to(directive) + fetch_has_many(directive) end private def fetch_belongs_to(directive) TableSaw::DependencyGraph::BelongsToDirectives.new(manifest, directive).call end def fetch_has_many(directive) TableSaw::DependencyGraph::HasManyDirectives.new(manifest, directive).call end def primary_key TableSaw.schema_cache.primary_keys(name) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems