Module: MetaDb

Defined in:
lib/meta_db.rb,
lib/meta_db/dump.rb,
lib/meta_db/version.rb,
lib/meta_db/db_object.rb,
lib/meta_db/connection.rb

Defined Under Namespace

Classes: CheckConstraint, Column, Connection, Constraint, Database, DbObject, Function, PostgresConnection, PostgresResult, PrimaryKeyConstraint, Procedure, ReferentialConstraint, Result, Schema, Table, Trigger, UniqueConstraint, View

Constant Summary collapse

VERSION =
"0.1.0"
CONSTRAINT_KINDS =
{
  PrimaryKeyConstraint => :primary_key,
  ReferentialConstraint => :foreign_key,
  UniqueConstraint => :unique,
  CheckConstraint => :check
}

Class Method Summary collapse

Class Method Details

.load_marshal(file) ⇒ Object



24
25
26
# File 'lib/meta_db.rb', line 24

def self.load_marshal(file)
  File.open(file) { |f| Marshal.load(f) }
end

.load_pg_conn(options) ⇒ Object

The options argument is a hash as PG::Connection options. :host, :port, :dbname, :user, and :password are some of the most used



34
35
36
# File 'lib/meta_db.rb', line 34

def self.load_pg_conn(options)
  PostgresConnection.open(options) { |conn| load_conn(conn) }
end

.load_yaml(file) ⇒ Object

TODO



13
14
15
# File 'lib/meta_db.rb', line 13

def self.load_yaml(file)
  YAML.load_file(file)
end

.save_marshal(db, file) ⇒ Object



28
29
30
# File 'lib/meta_db.rb', line 28

def self.save_marshal(db, file)
  File.open(file, 'w') { |f| Marshal.dump(db, f) }
end

.save_yaml(db, file, pretty: true) ⇒ Object



17
18
19
20
21
22
# File 'lib/meta_db.rb', line 17

def self.save_yaml(db, file, pretty: true)
  File.open(file, 'w') do |f|
    arg = pretty ? { :indentation => 3 } : {}
    f.write(YAML.dump(db, arg))
  end
end