Class: TripAdvisor::TranslationDBAccess
- Inherits:
-
Object
- Object
- TripAdvisor::TranslationDBAccess
- Defined in:
- lib/trip_advisor/db_access.rb
Instance Method Summary collapse
-
#connect ⇒ Object
Create the connection instance.
-
#disconnect ⇒ Object
Disconnect the back-end connection.
-
#getTranslation(key_name) ⇒ Object
Get translation for a single key.
-
#getTranslations(key_names) ⇒ Object
Get translations for keys in array.
Instance Method Details
#connect ⇒ Object
Create the connection instance.
7 8 9 10 11 12 |
# File 'lib/trip_advisor/db_access.rb', line 7 def connect @conn = PG.connect( :host => 'rivendell.tripadvisor.com', :dbname => 'tripmaster', :user => 'tripmaster_ro') end |
#disconnect ⇒ Object
Disconnect the back-end connection.
15 16 17 |
# File 'lib/trip_advisor/db_access.rb', line 15 def disconnect @conn.close end |
#getTranslation(key_name) ⇒ Object
Get translation for a single key
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/trip_advisor/db_access.rb', line 35 def getTranslation(key_name) queryString = "SELECT v.locale, k.name, v.value, k.status, k.note FROM t_translationkeys k INNER JOIN t_translationvalues v ON (k.id = v.translationid) WHERE k.name = '#{key_name}' ORDER BY v.locale DESC;" @conn.exec(queryString) do |result| result.each do |row| yield row if block_given? end end end |
#getTranslations(key_names) ⇒ Object
Get translations for keys in array
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/trip_advisor/db_access.rb', line 20 def getTranslations(key_names) queryString = "SELECT v.locale, k.name, v.value, k.status, k.note FROM t_translationkeys k INNER JOIN t_translationvalues v ON (k.id = v.translationid) WHERE k.name IN ('#{key_names.join("', '")}') ORDER BY v.locale DESC;" @conn.exec(queryString) do |result| result.each do |row| yield row if block_given? end end end |