lib/picky/backends/sqlite/basic.rb in picky-3.6.8 vs lib/picky/backends/sqlite/basic.rb in picky-3.6.9
- old
+ new
@@ -18,15 +18,15 @@
lazily_initialize_client
end
def initial
- @initial && @initial.clone || (@self_indexed ? self : {})
+ @initial && @initial.clone || (@self_indexed ? self.reset : {})
end
def empty
- @empty && @empty.clone || (@self_indexed ? self.reset_db.asynchronous : {})
+ @empty && @empty.clone || (@self_indexed ? self.reset.asynchronous : {})
end
def dump internal
dump_sqlite internal unless @self_indexed
self
@@ -43,11 +43,11 @@
def lazily_initialize_client
@db ||= SQLite3::Database.new cache_path
end
def dump_sqlite internal
- reset_db
+ reset
transaction do
# Note: Internal structures need to
# implement each.
#
@@ -56,20 +56,27 @@
db.execute 'insert into key_value values (?,?)', key.to_s, encoded_value
end
end
end
- def reset_db
+ def reset
create_directory cache_path
lazily_initialize_client
+ truncate_db
+
+ self
+ end
+
+ def truncate_db
# TODO Could this be replaced by a truncate statement?
#
- db.execute 'drop table if exists key_value;'
- db.execute 'create table key_value (key varchar(255), value text);'
- db.execute 'create index key_idx on key_value (key);'
+ drop_table
+ create_table
+ end
- self
+ def drop_table
+ db.execute 'drop table if exists key_value;'
end
def asynchronous
db.execute 'PRAGMA synchronous = OFF;'
self