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

#initialize(db_url) ⇒ Pg

Initializes PGConn connection.

Parameters:

  • db_url (String)

    postgres url to connect to (e.g. postgres://user:pw@host/db).



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

#repositories(opts = {}) ⇒ Array

Retrieve repositories.

Parameters:

  • opts (Hash) (defaults to: {})

    options, see Golem::DB.

Returns:

  • (Array)

    list of repotitories.



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

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

#setupPGRes

Setup schema.

Returns:

  • (PGRes)

    result.



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

#ssh_keys(opts = {}) ⇒ Array

Retrieve ssh keys.

Parameters:

  • opts (Hash) (defaults to: {})

    options, see Golem::DB.

Returns:

  • (Array)

    list of 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

#users(opts = {}) ⇒ Array

Retrieve users.

Parameters:

  • opts (Hash) (defaults to: {})

    options, see Golem::DB.

Returns:

  • (Array)

    list of users.



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

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