Class: Ductr::Postgres::Adapter

Inherits:
SequelBase::Adapter
  • Object
show all
Defined in:
lib/ductr/postgres/adapter.rb

Overview

The PostgreSQL adapter implement the required #open! and #close! methods to handle the database connection. The adapter is registered as :postgres to use it, add adapter: postgres to the YAML configuration e.g.:

# config/development.yml
adapters:
  some_postgres_database:
    adapter: postgres
    host: localhost
    user: postgres
    password: s3cr3t
    database: example

Instance Method Summary collapse

Instance Method Details

#close!void

This method returns an undefined value.

Closes the database connection.



42
43
44
# File 'lib/ductr/postgres/adapter.rb', line 42

def close!
  @db.disconnect
end

#new_connectionSequel::Database

Open a new connection, ensure to close it with the #disconnect method.

Returns:

  • (Sequel::Database)

    The database connection instance



51
52
53
54
55
56
57
58
# File 'lib/ductr/postgres/adapter.rb', line 51

def new_connection
  db = Sequel.postgres(**config)

  db.extension(:pg_streaming)
  db.stream_all_queries = true

  db
end

#open!Sequel::Database

Opens the database connection with the adapter's configuration.

Returns:

  • (Sequel::Database)

    The database connection instance



33
34
35
# File 'lib/ductr/postgres/adapter.rb', line 33

def open!
  @db = new_connection
end