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