Class: Ductr::SQLite::Adapter

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

Overview

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

# config/development.yml
adapters:
  some_sqlite_database:
    adapter: "sqlite"
    database: "example.db"

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



21
22
23
# File 'lib/ductr/sqlite/adapter.rb', line 21

def db
  @db
end

Instance Method Details

#close!void

This method returns an undefined value.

Closes the database connection. In the specific case of SQLite, we just destroy the connection instance.



38
39
40
# File 'lib/ductr/sqlite/adapter.rb', line 38

def close!
  @db = nil
end

#open!Sequel::Database

Opens the database connection with the adapter's configuration.

Returns:

  • (Sequel::Database)

    The database connection instance



28
29
30
# File 'lib/ductr/sqlite/adapter.rb', line 28

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