Class: Switches::Backends::Postgres::Table
- Inherits:
-
Object
- Object
- Switches::Backends::Postgres::Table
- Defined in:
- lib/switches/backends/postgres/table.rb
Constant Summary collapse
- UPDATE =
"UPDATE %s SET value = $1 WHERE key = $2"
- INSERT =
"INSERT INTO %s (key, value) values($2, $1)"
- SELECT =
"SELECT value FROM %s WHERE key = $1 LIMIT 1"
Instance Method Summary collapse
- #clear ⇒ Object
- #find(key) ⇒ Object
-
#initialize(name, connection) ⇒ Table
constructor
A new instance of Table.
- #upsert(key, value) ⇒ Object
Constructor Details
#initialize(name, connection) ⇒ Table
Returns a new instance of Table.
9 10 11 12 |
# File 'lib/switches/backends/postgres/table.rb', line 9 def initialize(name, connection) @name = name @connection = connection end |
Instance Method Details
#clear ⇒ Object
32 33 34 |
# File 'lib/switches/backends/postgres/table.rb', line 32 def clear @connection.execute("TRUNCATE TABLE #{@name}") end |
#find(key) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/switches/backends/postgres/table.rb', line 22 def find(key) result = @connection.execute(SELECT % @name, key) result.each do |row| return row["value"] end nil end |