Skip to content

Commit ac5f8c6

Browse files
committed
clarify Key is a string, either a SourceKey or an ID re #50
1 parent 87d0b71 commit ac5f8c6

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/jesse_database.erl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,17 @@ add_path(Path0, ParseFun, ValidationFun) ->
106106
%% from the internal storage. If there is no such key in the storage, an
107107
%% exception will be thrown.
108108
-spec load(Key :: string()) -> jesse:json_term() | no_return().
109-
load(Key) ->
109+
load(Key) when is_list(Key) ->
110110
Table = create_table(table_name()),
111-
case ets:match_object(Table, {'_', Key, '_', '_'}) of
112-
%% ID
113-
[{_SourceKey, Key, _Mtime, Schema}] ->
111+
%% ID
112+
Id = Key,
113+
case ets:match_object(Table, {'_', Id, '_', '_'}) of
114+
[{_SourceKey, Id, _Mtime, Schema}] ->
114115
Schema;
115116
[] ->
117+
%% SourceKey (URI)
116118
SourceKey = jesse_state:canonical_path(Key, Key),
117119
case ets:match_object(Table, {SourceKey, '_', '_', '_'}) of
118-
%% Source (URI)
119120
[{SourceKey, _Key, _Mtime, Schema}] ->
120121
Schema;
121122
_ ->
@@ -129,7 +130,7 @@ load(Key) ->
129130
%% http: or https: URI scheme. If this fails as well, an exception will be
130131
%% thrown.
131132
-spec load_uri(Key :: string()) -> jesse:json_term() | no_return().
132-
load_uri(Key) ->
133+
load_uri(Key) when is_list(Key) ->
133134
try
134135
load(Key)
135136
catch
@@ -147,12 +148,14 @@ load_all() ->
147148
%% @doc Deletes a schema definition from the internal storage associated with,
148149
%% or sourced with the key `Key'.
149150
-spec delete(Key :: string()) -> ok.
150-
delete(Key0) ->
151-
Key = jesse_state:canonical_path(Key0, Key0),
151+
delete(Key) when is_list(Key) ->
152152
Table = create_table(table_name()),
153-
SourceKey = Key,
153+
%% ID
154+
Id = Key,
155+
ets:match_delete(Table, {'_', Id, '_', '_'}),
156+
%% SourceKey (URI)
157+
SourceKey = jesse_state:canonical_path(Key, Key),
154158
ets:match_delete(Table, {SourceKey, '_', '_', '_'}),
155-
ets:match_delete(Table, {'_', Key, '_', '_'}),
156159
ok.
157160

158161
%%% Internal functions

0 commit comments

Comments
 (0)