class Switches::Backends::Postgres::Table
Constants
- INSERT
- SELECT
- UPDATE
Public Class Methods
new(name, connection)
click to toggle source
# File lib/switches/backends/postgres/table.rb, line 9 def initialize(name, connection) @name = name @connection = connection end
Public Instance Methods
clear()
click to toggle source
# File lib/switches/backends/postgres/table.rb, line 32 def clear @connection.execute("TRUNCATE TABLE #{@name}") end
find(key)
click to toggle source
# 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
upsert(key, value)
click to toggle source
# File lib/switches/backends/postgres/table.rb, line 14 def upsert(key, value) result = @connection.execute(UPDATE % @name, value, key) if result.cmd_tuples == 0 @connection.execute(INSERT % @name, value, key) end end