Sha256: 017322a4c1d580b022e9827f8716f69e2bfde369069847e8680678a86295c255

Contents?: true

Size: 1.04 KB

Versions: 22

Compression:

Stored size: 1.04 KB

Contents

module Picky

  module Backends

    class SQLite

      class Array < Basic

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

        def size
          result = db.execute 'SELECT COUNT(*) FROM key_value'
          result.first.first.to_i
        end

        def []= key, array
          unless array.empty?
            db.execute 'INSERT OR REPLACE INTO key_value (key,value) VALUES (?,?)',
                       key.to_s,
                       Yajl::Encoder.encode(array)
          end

          DirectlyManipulable.make self, array, key
          array
        end

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

          array = res.blank? ? [] : Yajl::Parser.parse(res.first.first)
          DirectlyManipulable.make self, array, key
          array
        end

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

      end

    end

  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
picky-4.4.2 lib/picky/backends/sqlite/array.rb
picky-4.4.1 lib/picky/backends/sqlite/array.rb
picky-4.4.0 lib/picky/backends/sqlite/array.rb
picky-4.3.2 lib/picky/backends/sqlite/array.rb
picky-4.3.1 lib/picky/backends/sqlite/array.rb
picky-4.3.0 lib/picky/backends/sqlite/array.rb
picky-4.2.4 lib/picky/backends/sqlite/array.rb
picky-4.2.3 lib/picky/backends/sqlite/array.rb
picky-4.2.2 lib/picky/backends/sqlite/array.rb
picky-4.2.1 lib/picky/backends/sqlite/array.rb
picky-4.2.0 lib/picky/backends/sqlite/array.rb
picky-4.1.0 lib/picky/backends/sqlite/array.rb
picky-4.0.9 lib/picky/backends/sqlite/array.rb
picky-4.0.8 lib/picky/backends/sqlite/array.rb
picky-4.0.7 lib/picky/backends/sqlite/array.rb
picky-4.0.6 lib/picky/backends/sqlite/array.rb
picky-4.0.5 lib/picky/backends/sqlite/array.rb
picky-4.0.4 lib/picky/backends/sqlite/array.rb
picky-4.0.3 lib/picky/backends/sqlite/array.rb
picky-4.0.1 lib/picky/backends/sqlite/array.rb