Class: DBMapping::PersonMapper
- Defined in:
- lib/data/sqlite/person_mapper.rb
Overview
Class to apply ER-mapping for Person::Person objects to a sqlite database
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#generate_persons ⇒ Array
public method to transform database persons to entity Person::Person.
-
#initialize(database) ⇒ PersonMapper
constructor
initialization.
-
#persist_persons(persons) ⇒ Object
method to persist a list of Person::Persons to the database.
-
#query_max_person_id ⇒ Integer
method to query the max id of the person table.
-
#query_person(id) ⇒ Person::Person | nil
method to search for a person by its id.
Methods inherited from Base
Constructor Details
#initialize(database) ⇒ PersonMapper
initialization
8 9 10 |
# File 'lib/data/sqlite/person_mapper.rb', line 8 def initialize(database) super(database) end |
Instance Method Details
#generate_persons ⇒ Array
public method to transform database persons to entity Person::Person
14 15 16 17 18 19 20 21 |
# File 'lib/data/sqlite/person_mapper.rb', line 14 def generate_persons results = @db_base.query_persons persons = Array.new() results.each { |result| persons << Person::Person.new(result["Name"], Integer(result["Id"])) } return persons end |
#persist_persons(persons) ⇒ Object
method to persist a list of Person::Persons to the database
25 26 27 28 29 30 |
# File 'lib/data/sqlite/person_mapper.rb', line 25 def persist_persons(persons) persons.each { |person| @db_base.insert_person(person.id, person.name) } nil end |
#query_max_person_id ⇒ Integer
method to query the max id of the person table
44 45 46 |
# File 'lib/data/sqlite/person_mapper.rb', line 44 def query_max_person_id check_max_id(@db_base.query_max_person_id.next) end |
#query_person(id) ⇒ Person::Person | nil
method to search for a person by its id
34 35 36 37 38 39 40 |
# File 'lib/data/sqlite/person_mapper.rb', line 34 def query_person(id) result = @db_base.query_person_by_id(id).next if (result != nil) return Person::Person.new(result["Name"], Integer(result["Id"])) end nil end |