Sha256: 6a486036028202e0b6957c461bdb05d5feb6cc67dd96c06e2650abacab37f15f

Contents?: true

Size: 1.23 KB

Versions: 25

Compression:

Stored size: 1.23 KB

Contents

require 'pg_conn'

module PgGraph::Data
  class Database
    # load data from connection
    def read_connection(conn)
      constrain conn, PgConn::Connection
      initialize_impl
      for schema in type.schemas
        for table in schema.tables
          for record in conn.records("select * from #{table.uid}")
            Record.new(self[schema.name][table.name], record)
          end
        end
      end
      self
    end

    # load data from hash. The hash can be produced by #to_h or #to_yaml
    #
    # TODO: Check for unknown keys
    def read_hash(hash)
      constrain hash, Hash
      initialize_impl

      # Works on to #to_h and #to_yaml hashes because it is easier to handle
      # the two formats dynamically than detecting which format to use
      for schema in type.schemas
        next if !hash.key?(schema.name)
        hash_schema = hash[schema.name]
        for table in schema.tables
          next if !hash[schema.name].key?(table.name)
          hash_table = hash_schema[table.name]
          records = hash_table.is_a?(Hash) ? hash_table.values : hash_table
          for record in records
            Record.new(self[schema.name][table.name], record)
          end
        end
      end
      self
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
pg_graph-0.5.2 lib/pg_graph/data/read.rb
pg_graph-0.5.1 lib/pg_graph/data/read.rb
pg_graph-0.5.0 lib/pg_graph/data/read.rb
pg_graph-0.4.2 lib/pg_graph/data/read.rb
pg_graph-0.4.1 lib/pg_graph/data/read.rb
pg_graph-0.4.0 lib/data/read.rb
pg_graph-0.3.6 lib/data/read.rb
pg_graph-0.3.5 lib/data/read.rb
pg_graph-0.3.4 lib/data/read.rb
pg_graph-0.3.3 lib/data/read.rb
pg_graph-0.3.2 lib/data/read.rb
pg_graph-0.3.1 lib/data/read.rb
pg_graph-0.3.0 lib/data/read.rb
pg_graph-0.2.1 lib/data/read.rb
pg_graph-0.2.0 lib/data/read.rb
pg_graph-0.1.9 lib/data/read.rb
pg_graph-0.1.8 lib/data/read.rb
pg_graph-0.1.7 lib/data/read.rb
pg_graph-0.1.6 lib/data/read.rb
pg_graph-0.1.5 lib/data/read.rb