Class: ROM::SQL::Repository
- Inherits:
-
Repository
- Object
- Repository
- ROM::SQL::Repository
- Includes:
- Options, Migration
- Defined in:
- lib/rom/sql/repository.rb
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 = {}) ⇒ Repository
constructor
SQL repository interface.
-
#use_logger(logger) ⇒ Object
Setup a logger.
Methods included from Migration
create, included, #migration, run, #run_migrations
Constructor Details
#connect(uri, options) ⇒ Repository #connect(connection) ⇒ Repository
SQL repository interface
55 56 57 58 59 60 61 62 63 |
# File 'lib/rom/sql/repository.rb', line 55 def initialize(uri, = {}) = self.class.option_definitions.names = .reject { |k,_| .include?(k) } @connection = connect(uri, ) @schema = connection.tables super(uri, .reject { |k,_| .keys.include?(k) }) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Return optionally configured logger
18 19 20 |
# File 'lib/rom/sql/repository.rb', line 18 def logger @logger end |
#schema ⇒ Array (readonly)
Returns a list of datasets inferred from table names
25 26 27 |
# File 'lib/rom/sql/repository.rb', line 25 def schema @schema end |
Class Method Details
.database_file?(scheme) ⇒ Boolean
30 31 32 |
# File 'lib/rom/sql/repository.rb', line 30 def self.database_file?(scheme) scheme.to_s.include?('sqlite') end |
Instance Method Details
#[](name) ⇒ Dataset
Return dataset with the given name
79 80 81 |
# File 'lib/rom/sql/repository.rb', line 79 def [](name) connection[name] end |
#dataset(name) ⇒ Dataset
Return dataset with the given name
102 103 104 |
# File 'lib/rom/sql/repository.rb', line 102 def dataset(name) connection[name] end |
#dataset?(name) ⇒ Boolean
Check if dataset exists
111 112 113 |
# File 'lib/rom/sql/repository.rb', line 111 def dataset?(name) schema.include?(name) end |
#disconnect ⇒ Object
Disconnect from database
68 69 70 |
# File 'lib/rom/sql/repository.rb', line 68 def disconnect connection.disconnect end |
#extend_command_class(klass, dataset) ⇒ Object
Extend database-specific behavior
Note: Currently, only postgres is supported.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rom/sql/repository.rb', line 123 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
90 91 92 93 |
# File 'lib/rom/sql/repository.rb', line 90 def use_logger(logger) @logger = logger connection.loggers << logger end |