Sha256: 86f572e02968749f1634d41883b4a27ed4b404ffde522f8fcca0259e91352ae4

Contents?: true

Size: 942 Bytes

Versions: 10

Compression:

Stored size: 942 Bytes

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 []= 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

10 entries across 10 versions & 1 rubygems

Version Path
picky-4.0.0pre5 lib/picky/backends/sqlite/array.rb
picky-4.0.0pre3 lib/picky/backends/sqlite/array.rb
picky-4.0.0pre2 lib/picky/backends/sqlite/array.rb
picky-4.0.0pre1 lib/picky/backends/sqlite/array.rb
picky-3.6.16 lib/picky/backends/sqlite/array.rb
picky-3.6.15 lib/picky/backends/sqlite/array.rb
picky-3.6.14 lib/picky/backends/sqlite/array.rb
picky-3.6.13 lib/picky/backends/sqlite/array.rb
picky-3.6.12 lib/picky/backends/sqlite/array.rb
picky-3.6.11 lib/picky/backends/sqlite/array.rb