Switch to CF KV instead of D1, more appropriate for the purpose
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
export async function onRequest(context) {
|
||||
const db = context.env.D1DB;
|
||||
const db = context.env.cryptopad;
|
||||
if (context.params.storage[0] == "delete") {
|
||||
const deleteReq = context.params.storage[1];
|
||||
await db.prepare("DELETE FROM data WHERE k=?").bind(deleteReq).run();
|
||||
await db.delete(deleteReq);
|
||||
return new Response();
|
||||
}
|
||||
const key = context.params.storage[0];
|
||||
@@ -13,10 +13,10 @@ export async function onRequest(context) {
|
||||
console.log("Inserting", key, value);
|
||||
// this doesn't use numbered parameters because miniflare behaves differently because better-sqlite3 doesn't handled numbered params well
|
||||
// CF really needs named support and better-sqlite3 really needs to fix this
|
||||
console.log(await db.prepare("INSERT INTO data (k, v) VALUES (?,?) ON CONFLICT(k) DO UPDATE SET v=? WHERE k=?").bind(key, value, value, key).run());
|
||||
await db.put(key, value);
|
||||
|
||||
return new Response();
|
||||
}
|
||||
const value = await db.prepare("SELECT v FROM data WHERE k=?").bind(key).first("v");
|
||||
const value = await db.get(key);
|
||||
return new Response(JSON.stringify(value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user