Class: Golem::DB::Pg
- Inherits:
-
Object
- Object
- Golem::DB::Pg
- Defined in:
- lib/golem/db/pg.rb
Overview
Postgres functionality. Requires pg
.
Instance Method Summary collapse
-
#initialize(db_url) ⇒ Pg
constructor
Initializes
PGConn
connection. -
#repositories(opts = {}) ⇒ Array
Retrieve repositories.
-
#setup ⇒ PGRes
Setup schema.
-
#ssh_keys(opts = {}) ⇒ Array
Retrieve ssh keys.
-
#users(opts = {}) ⇒ Array
Retrieve users.
Constructor Details
#initialize(db_url) ⇒ Pg
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
#repositories(opts = {}) ⇒ Array
Retrieve repositories.
22 23 24 25 |
# File 'lib/golem/db/pg.rb', line 22 def repositories(opts = {}) opts[:table] = :repositories get(opts) end |
#setup ⇒ PGRes
Setup schema.
37 38 39 |
# File 'lib/golem/db/pg.rb', line 37 def setup @connection.exec(File.read(File.(File.dirname(__FILE__) + '/postgres.sql'))) end |
#ssh_keys(opts = {}) ⇒ Array
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 |
#users(opts = {}) ⇒ Array
Retrieve users.
14 15 16 17 |
# File 'lib/golem/db/pg.rb', line 14 def users(opts = {}) opts[:table] = :users get(opts) end |