Skip to content

Commit

Permalink
encode values before add (insert) or put
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfmcr committed Dec 22, 2023
1 parent c2b4409 commit 76ba70a
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const insert = <StoreC extends t.Mixed>(
findStore(db, storeName),
O.fold(
() => reject(new Error('Store not found')),
() => {
const addRequest = getObjectStore(db, 'readwrite')(storeName).add(v);
(store) => {
const addRequest = getObjectStore(db, 'readwrite')(storeName).add(store.codec.encode(v));
addRequest.addEventListener('success', () => resolve(v));
handleRequestError(addRequest, reject);
}
Expand All @@ -90,18 +90,10 @@ export const put = <StoreC extends t.Mixed>(
findStore(db, storeName),
O.fold(
() => reject(new Error('Store not found')),
(c) => {
pipe(
c.codec.decode(v),
E.fold(
reject,
(item: StoreC['_A']) => {
const updateRequest = getObjectStore(db, 'readwrite')(storeName).put(item);
updateRequest.addEventListener('success', () => resolve(v));
handleRequestError(updateRequest, reject);
}
)
);
(store) => {
const updateRequest = getObjectStore(db, 'readwrite')(storeName).put(store.codec.encode(v));
updateRequest.addEventListener('success', () => resolve(v));
handleRequestError(updateRequest, reject);
}
)
);
Expand Down

0 comments on commit 76ba70a

Please sign in to comment.