Class: ROM::SQL::Gateway
- Inherits:
-
Gateway
- Object
- Gateway
- ROM::SQL::Gateway
- Includes:
- Options, Migration
- Defined in:
- lib/rom/sql/gateway.rb
Overview
SQL gateway
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Return optionally configured logger.
-
#schema ⇒ Array
readonly
Returns a list of datasets inferred from table names.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](name) ⇒ Dataset
Return dataset with the given name.
-
#dataset(name) ⇒ Dataset
Return dataset with the given name.
-
#dataset?(name) ⇒ Boolean
Check if dataset exists.
-
#disconnect ⇒ Object
Disconnect from database.
-
#extend_command_class(klass, dataset) ⇒ Object
Extend database-specific behavior.
-
#initialize(uri, options = {}) ⇒ Gateway
constructor
SQL gateway interface.
-
#use_logger(logger) ⇒ Object
Setup a logger.
Methods included from Migration
create, included, #migration, #pending_migrations?, run, #run_migrations
Constructor Details
#connect(uri, options) ⇒ Gateway #connect(connection) ⇒ Gateway
SQL gateway interface
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rom/sql/gateway.rb', line 68 def initialize(uri, = {}) = self.class.option_definitions.names = .reject { |k, _| .include?(k) } @connection = connect(uri, ) @schema = connection.tables add_extensions(Array([:extensions])) if [:extensions] super(uri, .reject { |k, _| .keys.include?(k) }) self.class.instance = self end |
Class Attribute Details
.instance ⇒ Object
23 24 25 |
# File 'lib/rom/sql/gateway.rb', line 23 def instance @instance end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Return optionally configured logger
31 32 33 |
# File 'lib/rom/sql/gateway.rb', line 31 def logger @logger end |
#schema ⇒ Array (readonly)
Returns a list of datasets inferred from table names
38 39 40 |
# File 'lib/rom/sql/gateway.rb', line 38 def schema @schema end |
Class Method Details
.database_file?(scheme) ⇒ Boolean
43 44 45 |
# File 'lib/rom/sql/gateway.rb', line 43 def self.database_file?(scheme) scheme.to_s.include?('sqlite') end |
Instance Method Details
#[](name) ⇒ Dataset
Return dataset with the given name
95 96 97 |
# File 'lib/rom/sql/gateway.rb', line 95 def [](name) connection[name] end |
#dataset(name) ⇒ Dataset
Return dataset with the given name
118 119 120 |
# File 'lib/rom/sql/gateway.rb', line 118 def dataset(name) connection[name] end |
#dataset?(name) ⇒ Boolean
Check if dataset exists
127 128 129 |
# File 'lib/rom/sql/gateway.rb', line 127 def dataset?(name) schema.include?(name) end |
#disconnect ⇒ Object
Disconnect from database
84 85 86 |
# File 'lib/rom/sql/gateway.rb', line 84 def disconnect connection.disconnect end |
#extend_command_class(klass, dataset) ⇒ Object
Extend database-specific behavior
Note: Currently, only postgres is supported.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rom/sql/gateway.rb', line 139 def extend_command_class(klass, dataset) type = dataset.db.database_type if type == :postgres ext = if klass < Commands::Create Commands::Postgres::Create elsif klass < Commands::Update Commands::Postgres::Update end klass.send(:include, ext) if ext end klass end |
#use_logger(logger) ⇒ Object
Setup a logger
106 107 108 109 |
# File 'lib/rom/sql/gateway.rb', line 106 def use_logger(logger) @logger = logger connection.loggers << logger end |