Class: ROM::SQL::Repository
- Inherits:
-
Repository
- Object
- Repository
- ROM::SQL::Repository
- 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.
Constructor Details
#connect(uri, options) ⇒ Repository #connect(connection) ⇒ Repository
SQL repository interface
51 52 53 54 |
# File 'lib/rom/sql/repository.rb', line 51 def initialize(uri, = {}) @connection = connect(uri, ) @schema = connection.tables end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Return optionally configured logger
14 15 16 |
# File 'lib/rom/sql/repository.rb', line 14 def logger @logger end |
#schema ⇒ Array (readonly)
Returns a list of datasets inferred from table names
21 22 23 |
# File 'lib/rom/sql/repository.rb', line 21 def schema @schema end |
Class Method Details
.database_file?(scheme) ⇒ Boolean
26 27 28 |
# File 'lib/rom/sql/repository.rb', line 26 def self.database_file?(scheme) scheme.to_s.include?('sqlite') end |
Instance Method Details
#[](name) ⇒ Dataset
Return dataset with the given name
70 71 72 |
# File 'lib/rom/sql/repository.rb', line 70 def [](name) connection[name] end |
#dataset(name) ⇒ Dataset
Return dataset with the given name
93 94 95 |
# File 'lib/rom/sql/repository.rb', line 93 def dataset(name) connection[name] end |
#dataset?(name) ⇒ Boolean
Check if dataset exists
102 103 104 |
# File 'lib/rom/sql/repository.rb', line 102 def dataset?(name) schema.include?(name) end |
#disconnect ⇒ Object
Disconnect from database
59 60 61 |
# File 'lib/rom/sql/repository.rb', line 59 def disconnect connection.disconnect end |
#extend_command_class(klass, dataset) ⇒ Object
Extend database-specific behavior
Note: Currently, only postgres is supported.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rom/sql/repository.rb', line 114 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
81 82 83 84 |
# File 'lib/rom/sql/repository.rb', line 81 def use_logger(logger) @logger = logger connection.loggers << logger end |