Class: Pgtk::Wire::Direct

Inherits:
Object
  • Object
show all
Defined in:
lib/pgtk/wire.rb

Overview

Simple wire with details.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2019-2026 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, dbname:, user:, password:, **opts) ⇒ Direct

Constructor.

Parameters:

  • host (String)

    Host name of the PostgreSQL server

  • port (Integer)

    Port number of the PostgreSQL server

  • dbname (String)

    Database name

  • user (String)

    Username

  • password (String)

    Password

  • opts (Hash)

    Extra options forwarded to PG.connect (e.g. sslmode, connect_timeout, keepalives, keepalives_idle, application_name)

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
# File 'lib/pgtk/wire.rb', line 31

def initialize(host:, port:, dbname:, user:, password:, **opts)
  raise(ArgumentError, "The host can't be nil") if host.nil?
  @host = host
  raise(ArgumentError, "The port can't be nil") if port.nil?
  @port = port
  @dbname = dbname
  @user = user
  @password = password
  @opts = opts
end

Instance Method Details

#connectionObject

Create a new connection to PostgreSQL server.



43
44
45
# File 'lib/pgtk/wire.rb', line 43

def connection
  PG.connect(dbname: @dbname, host: @host, port: @port, user: @user, password: @password, **@opts)
end