Class: Geode::SequelStore
Overview
A store that uses a relational database supported by Sequel instead of Redis. This is mainly useful for Heroku, where persistent Postgres is free, but the same is not true of Redis. Unless you have a similarly good reason to use this class, use ‘RedisStore` instead.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(name, connection = nil) ⇒ SequelStore
constructor
Connect to a store held in a relational database supported by Sequel.
- #open ⇒ Object
Methods inherited from Store
Constructor Details
#initialize(name, connection = nil) ⇒ SequelStore
Connect to a store held in a relational database supported by Sequel. A table named ‘geode` will be created and used to store the data.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/geode/sequel.rb', line 16 def initialize(name, connection = nil) super connection ||= { adapter: 'postgres' } db = Sequel.connect(connection) db.create_table? :geode do String :name, primary_key: true File :value end @db = db[:geode] end |
Instance Method Details
#destroy ⇒ Object
43 44 45 46 |
# File 'lib/geode/sequel.rb', line 43 def destroy @db.where(name: @name).delete nil end |
#open ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/geode/sequel.rb', line 29 def open store = @db.where(name: @name) table = if store.empty? store.insert(name: @name, value: '') {} else Marshal.load(store.first[:value]) end (yield table).tap do store.update(value: Sequel.blob(Marshal.dump(table))) end end |