Skip to content

Commit

Permalink
Use production Deno kv
Browse files Browse the repository at this point in the history
  • Loading branch information
coddeys committed Jun 27, 2024
1 parent 236e9b2 commit a6a4d27
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
8 changes: 4 additions & 4 deletions routes/api/bids/[id].ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const handler: Handlers<Bid | null> = {
async GET(_req, ctx) {
const kv = await Deno.openKv(
"https://api.deno.com/databases/824bd08c-5681-4772-947f-b1ef806f3747/connect",
);
// const kv = await Deno.openKv();
// const kv = await Deno.openKv(
// "https://api.deno.com/databases/824bd08c-5681-4772-947f-b1ef806f3747/connect",
// );
const kv = await Deno.openKv();
const id = ctx.params.id;
const key = ["bid", id];
const bid = (await kv.get<Bid>(key)).value!;
Expand Down
10 changes: 2 additions & 8 deletions routes/api/bids/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
export const handler: Handlers<Bid | null> = {
async POST(req, _ctx) {
const bid = (await req.json()) as Bid;
const kv = await Deno.openKv(
"https://api.deno.com/databases/824bd08c-5681-4772-947f-b1ef806f3747/connect",
);
// const kv = await Deno.openKv();
const kv = await Deno.openKv();
const bidKey = ["bid", bid.txHash];
const ok = await kv.atomic().set(bidKey, bid).commit();
if (!ok) throw new Error("Something went wrong.");
return new Response(JSON.stringify(bid));
},

async GET(_req, ctx) {
const kv = await Deno.openKv(
"https://api.deno.com/databases/824bd08c-5681-4772-947f-b1ef806f3747/connect",
);
// const kv = await Deno.openKv();
const kv = await Deno.openKv();
const iter = await kv.list({ prefix: ["bid"] });
const bids = [];
for await (const res of iter) bids.push(res);
Expand Down
5 changes: 1 addition & 4 deletions routes/bids/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ interface Data {
export const handler: Handlers<Data> = {
async GET(_req, ctx) {
const scriptAddress = ctx.params.id;
const kv = await Deno.openKv(
"https://api.deno.com/databases/824bd08c-5681-4772-947f-b1ef806f3747/connect",
);
// const kv = await Deno.openKv();
const kv = await Deno.openKv();
const resp = await kv.get(["bid", scriptAddress]);
const bid = resp.value;
return ctx.render({ bid });
Expand Down
9 changes: 5 additions & 4 deletions routes/bids/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { env } from "../../config.ts";

export const handler: Handlers<Data> = {
async GET(_req, ctx) {
const kv = await Deno.openKv(
"https://api.deno.com/databases/824bd08c-5681-4772-947f-b1ef806f3747/connect",
);
// const kv = await Deno.openKv();
// const kv = await Deno.openKv(
// "https://api.deno.com/databases/824bd08c-5681-4772-947f-b1ef806f3747/connect",
// );

const kv = await Deno.openKv();
const iter = await kv.list({ prefix: ["bid"] });
// delete all
// for await (const res of iter) kv.delete(res.key)
Expand Down

0 comments on commit a6a4d27

Please sign in to comment.