Sha256: 060207d1fd689632140c20cf9d961933f9bc93e8d678fab29942811ec6aa8b0b

Contents?: true

Size: 761 Bytes

Versions: 86

Compression:

Stored size: 761 Bytes

Contents

module Picky

  module Backends

    class SQLite

      class Value < Basic

        def create_table
          db.execute 'create table key_value (key varchar(255) PRIMARY KEY, value text);'
        end

        def []= key, value
          db.execute 'INSERT OR REPLACE INTO key_value (key, value) VALUES (?,?)',
                     key.to_s,
                     MultiJson.encode(value)

          value
        end

        def [] key
          res = db.execute "SELECT value FROM key_value WHERE key = ? LIMIT 1;", key.to_s
          return nil if res.empty?

          MultiJson.decode res.first.first
        end

        def delete key
          db.execute "DELETE FROM key_value WHERE key = (?)", key.to_s
        end

      end

    end

  end

end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
picky-4.22.0 lib/picky/backends/sqlite/value.rb
picky-4.21.2 lib/picky/backends/sqlite/value.rb
picky-4.21.1 lib/picky/backends/sqlite/value.rb
picky-4.21.0 lib/picky/backends/sqlite/value.rb
picky-4.20.2 lib/picky/backends/sqlite/value.rb
picky-4.20.1 lib/picky/backends/sqlite/value.rb
picky-4.20.0 lib/picky/backends/sqlite/value.rb
picky-4.19.7 lib/picky/backends/sqlite/value.rb
picky-4.19.6 lib/picky/backends/sqlite/value.rb
picky-4.19.5 lib/picky/backends/sqlite/value.rb
picky-4.19.4 lib/picky/backends/sqlite/value.rb
picky-4.19.3 lib/picky/backends/sqlite/value.rb
picky-4.19.2 lib/picky/backends/sqlite/value.rb
picky-4.19.1 lib/picky/backends/sqlite/value.rb
picky-4.19.0 lib/picky/backends/sqlite/value.rb
picky-4.18.0 lib/picky/backends/sqlite/value.rb
picky-4.17.1 lib/picky/backends/sqlite/value.rb
picky-4.17.0 lib/picky/backends/sqlite/value.rb
picky-4.16.0 lib/picky/backends/sqlite/value.rb
picky-4.15.1 lib/picky/backends/sqlite/value.rb