Module: Adapter::Postgres

Defined in:
lib/adapter/postgres.rb,
lib/adapter/postgres/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#clearObject



33
34
35
# File 'lib/adapter/postgres.rb', line 33

def clear
  res = client.exec("UPDATE #{table_name} SET data = ''::hstore")
end

#delete(key) ⇒ Object



26
27
28
29
30
31
# File 'lib/adapter/postgres.rb', line 26

def delete(key)
  if value = read(key)
    res = client.exec("UPDATE #{table_name} SET data = delete(data,'#{key_for(key)}')")
  end
  value
end

#key?(key) ⇒ Boolean

I don’t think this is ever used?

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/adapter/postgres.rb', line 11

def key?(key)
  res = client.exec("SELECT exist(data,'#{key_for(key)}') AS v FROM #{table_name}")
  res.getvalue(0,0) != "f"
end

#read(key) ⇒ Object



16
17
18
19
# File 'lib/adapter/postgres.rb', line 16

def read(key)
  res = client.exec("SELECT data -> '#{key_for(key)}' AS v FROM #{table_name}")
  decode(res.getvalue(0,0))
end

#table_nameObject



6
7
8
# File 'lib/adapter/postgres.rb', line 6

def table_name
  "generic_hstore_table"
end

#write(key, value) ⇒ Object



21
22
23
24
# File 'lib/adapter/postgres.rb', line 21

def write(key, value)
  res = client.exec("UPDATE #{table_name} SET data = data || hstore('#{key_for(key)}','#{encode(value)}')")
  value
end