Skip to content

Commit 83a1dc5

Browse files
committed
add a clear! method to litekd to clear all data
1 parent b1727e4 commit 83a1dc5

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/litestack/litekd.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def self.configure(options = {})
2626
@@options = options
2727
end
2828

29+
def self.clear!
30+
connection.transaction(:immediate) do
31+
connection.clear_all_scalars
32+
connection.clear_all_composites
33+
end
34+
end
35+
2936
# scalars
3037
def self.string(key, **args) = Scalar.new(key, typed: :string, **args)
3138
def self.integer(key, **args) = Scalar.new(key, typed: :integer, **args)

lib/litestack/sql/litekd.sql.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ schema:
2121
CREATE INDEX direct_value_index ON composites(key, value)
2222
2323
stmts:
24+
25+
clear_all_scalars: >
26+
DELETE FROM scalars;
27+
28+
clear_all_composites: >
29+
DELETE FROM composites;
30+
2431
write_scalar_value: >
2532
INSERT OR REPLACE INTO scalars(key, value, expires_in)
2633
VALUES (:key, :value, unixepoch('subsec') + :expires_in);

test/test_litekd.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def generate_names_key
3434
class TestLitekd < Minitest::Test
3535

3636
def setup
37+
Kredis.clear!
3738
end
3839

3940
def test_string

0 commit comments

Comments
 (0)