Class: Ductr::Postgres::Adapter

Inherits:
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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dbSequel::Database? (readonly)

Returns The database connection instance.

Returns:

  • (Sequel::Database, nil)

    The database connection instance



29
30
31
# File 'lib/ductr/postgres/adapter.rb', line 29

def db
  @db
end

Instance Method Details

#close!void

This method returns an undefined value.

Closes the database connection.



50
51
52
# File 'lib/ductr/postgres/adapter.rb', line 50

def close!
  @db.disconnect
end

#open!Sequel::Database

Opens the database connection with the adapter's configuration.

Returns:

  • (Sequel::Database)

    The database connection instance



36
37
38
39
40
41
42
43
# File 'lib/ductr/postgres/adapter.rb', line 36

def open!
  @db = Sequel.postgres(**config)

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

  @db
end