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"
Hi, I am making like a voting thing with many to many relationship, and this one is causing me a problem. schema.ts
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),
})
);
api
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")
});
}
I have check the payload which is also correct, and in correct type :3
3 Replies
tomeverson
tomeversonOP15mo ago
when I tested like
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))
it shows
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);
this is insert command
Andrii Sherman
Andrii Sherman15mo ago
I thinks this may be some trouble on Neon side
tomeverson
tomeversonOP15mo ago
yep reset the DB url and it works
Want results from more Discord servers?
Add your server