Skip to content

Commit

Permalink
add a clear! method to litekd to clear all data
Browse files Browse the repository at this point in the history
  • Loading branch information
oldmoe committed Jul 21, 2024
1 parent b1727e4 commit 83a1dc5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/litestack/litekd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def self.configure(options = {})
@@options = options
end

def self.clear!
connection.transaction(:immediate) do
connection.clear_all_scalars
connection.clear_all_composites
end
end

# scalars
def self.string(key, **args) = Scalar.new(key, typed: :string, **args)
def self.integer(key, **args) = Scalar.new(key, typed: :integer, **args)
Expand Down
7 changes: 7 additions & 0 deletions lib/litestack/sql/litekd.sql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ schema:
CREATE INDEX direct_value_index ON composites(key, value)
stmts:

clear_all_scalars: >
DELETE FROM scalars;
clear_all_composites: >
DELETE FROM composites;
write_scalar_value: >
INSERT OR REPLACE INTO scalars(key, value, expires_in)
VALUES (:key, :value, unixepoch('subsec') + :expires_in);
Expand Down
1 change: 1 addition & 0 deletions test/test_litekd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def generate_names_key
class TestLitekd < Minitest::Test

def setup
Kredis.clear!
end

def test_string
Expand Down

0 comments on commit 83a1dc5

Please sign in to comment.