Class: Golem::DB::Pg

Inherits:
Object
  • Object
show all
Defined in:
lib/golem/db/pg.rb

Overview

Postgres functionality. Requires pg.

Instance Method Summary (collapse)

Constructor Details

- (Pg) initialize(db_url)

Initializes PGConn connection.



7
8
9
# File 'lib/golem/db/pg.rb', line 7

def initialize(db_url)
	@connection ||= ::PGconn.connect(*(db_url.match(/\Apostgres:\/\/([^:]+):([^@]+)@([^\/]+)\/(.+)\z/) {|m| [m[3], 5432, nil, nil, m[4], m[1], m[2]]}))
end

Instance Method Details

- (Array) repositories(opts = {})

Retrieve repositories.



22
23
24
25
# File 'lib/golem/db/pg.rb', line 22

def repositories(opts = {})
	opts[:table] = :repositories
	get(opts)
end

- (PGRes) setup

Setup schema.



37
38
39
# File 'lib/golem/db/pg.rb', line 37

def setup
	@connection.exec(File.read(File.expand_path(File.dirname(__FILE__) + '/postgres.sql')))
end

- (Array) ssh_keys(opts = {})

Retrieve ssh keys.



30
31
32
33
# File 'lib/golem/db/pg.rb', line 30

def ssh_keys(opts = {})
	opts[:table] = "keys join users on keys.user_name=users.name"
	get(opts)
end

- (Array) users(opts = {})

Retrieve users.



14
15
16
17
# File 'lib/golem/db/pg.rb', line 14

def users(opts = {})
	opts[:table] = :users
	get(opts)
end