Class: PgCtrl::RDBMS
- Inherits:
-
Object
- Object
- PgCtrl::RDBMS
- Includes:
- Utils
- Defined in:
- lib/pg_ctrl/db.rb,
lib/pg_ctrl/load.rb
Constant Summary collapse
- LOAD_USERS_QUERY =
%( select oid as OID, rolname as NAME, rolsuper as IS_SUPERUSER, rolcreaterole as CAN_CREATE_ROLE, rolcreatedb as CAN_CREATE_DB, rolcanlogin as CAN_LOGIN, case when rolname = current_user then true else false end as IS_CURRENT_USER from pg_roles )- LOAD_DATABASES_QUERY =
%( select pg_database.oid as OID, datname as NAME, rolname as OWNER, pg_encoding_to_char(encoding) as ENCODING, datcollate as LC_COLLATE, datctype as LC_CTYPE, datistemplate as IS_TEMPLATE, datallowconn as CAN_CONNECT, datacl as ACL, case when datname = current_database() then true else false end as IS_CURRENT_DATABASE from pg_database join pg_roles on datdba = pg_roles.oid )
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#databases ⇒ Object
readonly
Returns the value of attribute databases.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#user ⇒ Object
readonly
Current user and database.
-
#users ⇒ Object
readonly
Users and databases indexed by name.
Instance Method Summary collapse
- #host ⇒ Object
-
#initialize(*args) ⇒ RDBMS
constructor
Arguments initialize(PGconn args) initialize(PGconn object).
- #ip? ⇒ Boolean
- #load_data ⇒ Object
- #load_databases ⇒ Object
- #load_users ⇒ Object
- #port ⇒ Object
- #to_s ⇒ Object
Methods included from Utils
Constructor Details
#initialize(*args) ⇒ RDBMS
Arguments
initialize(PGconn args)
initialize(PGconn object)
65 66 67 68 69 70 71 72 73 |
# File 'lib/pg_ctrl/db.rb', line 65 def initialize(*args) if args.size == 1 && PGconn === args[0] @connection = args[0] else @connection = PGconn.new(args[0]) end @id = (!host || host == "127.0.0.1" ? "localhost" : host) load_data end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
48 49 50 |
# File 'lib/pg_ctrl/db.rb', line 48 def connection @connection end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
59 60 61 |
# File 'lib/pg_ctrl/db.rb', line 59 def database @database end |
#databases ⇒ Object (readonly)
Returns the value of attribute databases.
55 56 57 |
# File 'lib/pg_ctrl/db.rb', line 55 def databases @databases end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
46 47 48 |
# File 'lib/pg_ctrl/db.rb', line 46 def id @id end |
#user ⇒ Object (readonly)
Current user and database
58 59 60 |
# File 'lib/pg_ctrl/db.rb', line 58 def user @user end |
#users ⇒ Object (readonly)
Users and databases indexed by name
54 55 56 |
# File 'lib/pg_ctrl/db.rb', line 54 def users @users end |
Instance Method Details
#host ⇒ Object
50 |
# File 'lib/pg_ctrl/db.rb', line 50 def host() @connection.host end |
#ip? ⇒ Boolean
49 |
# File 'lib/pg_ctrl/db.rb', line 49 def ip?() !host.nil? end |
#load_data ⇒ Object
72 73 74 75 76 77 |
# File 'lib/pg_ctrl/load.rb', line 72 def load_data @users = RDBMSObjectSet.new @databases = RDBMSObjectSet.new load_users load_databases end |
#load_databases ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/pg_ctrl/load.rb', line 64 def load_databases @connection.each_hash(LOAD_DATABASES_QUERY) { |r| @databases.add \ Database.new(self, r[:oid], r[:name], @users[r[:owner]], r) @database = @databases[r[:name]] if r[:is_current_database] } end |
#load_users ⇒ Object
41 42 43 44 45 46 |
# File 'lib/pg_ctrl/load.rb', line 41 def load_users @connection.each_hash(LOAD_USERS_QUERY) { |r| @users.add User.new(self, r[:oid], r[:name], r) @user = @users[r[:name]] if r[:is_current_user] } end |
#port ⇒ Object
51 |
# File 'lib/pg_ctrl/db.rb', line 51 def port() @connection.port.to_i end |
#to_s ⇒ Object
75 |
# File 'lib/pg_ctrl/db.rb', line 75 def to_s() @id end |