Prepared Statement doesn't exist
"message": "db error: ERROR: prepared statement \"s114\" does not exist\n\nCaused by:\n ERROR: prepared statement \"s114\" does not exist"
"message": "db error: ERROR: prepared statement \"s114\" does not exist\n\nCaused by:\n ERROR: prepared statement \"s114\" does not exist"
export const hubVotes = pgTable(
"HubVotes",
{
userId: integer("UserId")
.notNull(),
hubPostId: integer("HubId")
.notNull(),
vote: voteEnum("Vote").notNull(),
},
(t) => ({
pk: primaryKey(t.userId, t.hubPostId),
})
);
export const hubVotes = pgTable(
"HubVotes",
{
userId: integer("UserId")
.notNull(),
hubPostId: integer("HubId")
.notNull(),
vote: voteEnum("Vote").notNull(),
},
(t) => ({
pk: primaryKey(t.userId, t.hubPostId),
})
);
route.patch("/", async (req, res) => {
const vote = req.body as NewHubVote;
console.log(req.userId, vote.hubPostId)
//* Check The Existing Vote
const existingvote = await searchHubVote(req.userId);
if (existingvote) {
//* If the vote are same, remove the votes
if (existingvote.vote === vote.vote) {
await removeHubVote({ userId: req.userId });
res.status(200)
return res.send("OK");
}
await updateHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK");
}
//* If no Vote Existed, Create a New One
await createHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK")
});
}
route.patch("/", async (req, res) => {
const vote = req.body as NewHubVote;
console.log(req.userId, vote.hubPostId)
//* Check The Existing Vote
const existingvote = await searchHubVote(req.userId);
if (existingvote) {
//* If the vote are same, remove the votes
if (existingvote.vote === vote.vote) {
await removeHubVote({ userId: req.userId });
res.status(200)
return res.send("OK");
}
await updateHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK");
}
//* If no Vote Existed, Create a New One
await createHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK")
});
}
3 Replies
when I tested like
it shows
this is insert command
import { createHubVote } from "@/func/hub/vote";
const vote = async () => {
console.log("Testing..")
await createHubVote({
userId: 1,
hubPostId: 1,
vote: "LIKE"
})
}
vote().then(res => console.log(res)).catch(e => console.log(e))
import { createHubVote } from "@/func/hub/vote";
const vote = async () => {
console.log("Testing..")
await createHubVote({
userId: 1,
hubPostId: 1,
vote: "LIKE"
})
}
vote().then(res => console.log(res)).catch(e => console.log(e))
NeonDbError: connection closed
at <anonymous> (/Users/tom/Desktop/server/node_modules/@neondatabase/serverless/index.js:1530:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at createHubVote (/Users/tom/Desktop/server/func/hub/vote.ts:7:3)
at vote (/Users/tom/Desktop/server/src/test.ts:5:5) {
code: null,
sourceError: undefined
}
NeonDbError: connection closed
at <anonymous> (/Users/tom/Desktop/server/node_modules/@neondatabase/serverless/index.js:1530:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at createHubVote (/Users/tom/Desktop/server/func/hub/vote.ts:7:3)
at vote (/Users/tom/Desktop/server/src/test.ts:5:5) {
code: null,
sourceError: undefined
}
export const createHubVote = async (vote: NewHubVote) =>
await db.insert(hubVotes).values(vote);
export const createHubVote = async (vote: NewHubVote) =>
await db.insert(hubVotes).values(vote);
I thinks this may be some trouble on Neon side
yep
reset the DB url and it works