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.
Instance Method Summary collapse
-
#[](name) ⇒ Dataset
Return dataset with the given name.
-
#create_table(*args, &block) ⇒ Object
Create a table using the configured connection.
-
#dataset(name) ⇒ Dataset
Return dataset with the given name.
-
#dataset?(name) ⇒ Boolean
Check if dataset exists.
-
#disconnect ⇒ Object
Disconnect from database.
-
#drop_table(*args, &block) ⇒ Object
Drops a table.
-
#extend_command_class(klass, dataset) ⇒ Object
Extend database-specific behavior.
-
#initialize(uri, options = {}) ⇒ Gateway
constructor
SQL gateway interface.
-
#schema ⇒ Array
Returns a list of datasets inferred from table names.
-
#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
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rom/sql/gateway.rb', line 54 def initialize(uri, = {}) = self.class.option_definitions.names = .reject { |k, _| .include?(k) } @connection = connect(uri, ) 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 |
Instance Method Details
#[](name) ⇒ Dataset
Return dataset with the given name
80 81 82 |
# File 'lib/rom/sql/gateway.rb', line 80 def [](name) connection[name] end |
#create_table(*args, &block) ⇒ Object
Create a table using the configured connection
144 145 146 |
# File 'lib/rom/sql/gateway.rb', line 144 def create_table(*args, &block) connection.create_table(*args, &block) end |
#dataset(name) ⇒ Dataset
Return dataset with the given name
103 104 105 |
# File 'lib/rom/sql/gateway.rb', line 103 def dataset(name) connection[name] end |
#dataset?(name) ⇒ Boolean
Check if dataset exists
112 113 114 |
# File 'lib/rom/sql/gateway.rb', line 112 def dataset?(name) schema.include?(name) end |
#disconnect ⇒ Object
Disconnect from database
69 70 71 |
# File 'lib/rom/sql/gateway.rb', line 69 def disconnect connection.disconnect end |
#drop_table(*args, &block) ⇒ Object
Drops a table
151 152 153 |
# File 'lib/rom/sql/gateway.rb', line 151 def drop_table(*args, &block) connection.drop_table(*args, &block) end |
#extend_command_class(klass, dataset) ⇒ Object
Extend database-specific behavior
Note: Currently, only postgres is supported.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rom/sql/gateway.rb', line 124 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 |
#schema ⇒ Array
Returns a list of datasets inferred from table names
160 161 162 |
# File 'lib/rom/sql/gateway.rb', line 160 def schema @schema ||= connection.tables end |
#use_logger(logger) ⇒ Object
Setup a logger
91 92 93 94 |
# File 'lib/rom/sql/gateway.rb', line 91 def use_logger(logger) @logger = logger connection.loggers << logger end |