Class: Koine::Repository::Persistence::Adapter::Sql
- Inherits:
-
Koine::Repository::Persistence::Adapter
- Object
- Koine::Repository::Persistence::Adapter
- Koine::Repository::Persistence::Adapter::Sql
- Defined in:
- lib/koine/repository/persistence/adapter/sql.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#id_field ⇒ Object
readonly
Returns the value of attribute id_field.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #delete_where(criterias) ⇒ Object
- #exists?(criterias) ⇒ Boolean
- #find(id) ⇒ Object
- #find_all_by(criterias) ⇒ Object
- #find_one_by(criterias) ⇒ Object
-
#initialize(adapter, table_name, id_field = :id) ⇒ Sql
constructor
A new instance of Sql.
- #insert(values) ⇒ Object
- #update_where(criterias, values) ⇒ Object
Constructor Details
#initialize(adapter, table_name, id_field = :id) ⇒ Sql
Returns a new instance of Sql.
8 9 10 11 12 13 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 8 def initialize(adapter, table_name, id_field = :id) @adapter = adapter @table_name = table_name @table = adapter[table_name] @id_field = id_field end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 6 def adapter @adapter end |
#id_field ⇒ Object (readonly)
Returns the value of attribute id_field.
6 7 8 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 6 def id_field @id_field end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
6 7 8 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 6 def table @table end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
6 7 8 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 6 def table_name @table_name end |
Instance Method Details
#delete_where(criterias) ⇒ Object
39 40 41 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 39 def delete_where(criterias) find_all_by(criterias).delete end |
#exists?(criterias) ⇒ Boolean
15 16 17 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 15 def exists?(criterias) table.where(criterias).limit(2).count > 0 end |
#find(id) ⇒ Object
19 20 21 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 19 def find(id) find_one_by(id_field => id) end |
#find_all_by(criterias) ⇒ Object
27 28 29 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 27 def find_all_by(criterias) table.where(criterias) end |
#find_one_by(criterias) ⇒ Object
23 24 25 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 23 def find_one_by(criterias) table.where(criterias).first end |
#insert(values) ⇒ Object
31 32 33 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 31 def insert(values) table.insert(values) end |
#update_where(criterias, values) ⇒ Object
35 36 37 |
# File 'lib/koine/repository/persistence/adapter/sql.rb', line 35 def update_where(criterias, values) find_all_by(criterias).update(values) end |