adam boukhris
adam boukhris
Explore posts from servers
PPrisma
Created by adam boukhris on 1/4/2025 in #help-and-questions
Sveltekit not receiving real-time data
Hello devs , i was trying to add real time events in my sveltekit app and with the release of prisma pulse and prisma postgreSQL so i added these features to my app but i had problem with prisma pulse , when i create a new DB i receive events when a change happens only in a short period of time and it stops working and i'm not having any error , in my pluse dashboard it says Replication slot status Unavailable idk if it means something , and this is my code , it will be nice of you if you take a look maybe i was doing things not in the right way
//api/+server.js
import { prisma } from "$lib/index.js";

export async function GET({ request }) {
const stream = new ReadableStream({
async start(controller) {
async function main() {
try {
const prismaStream = await prisma.links.stream();

for await (const event of prismaStream) {
console.log("Received event:", event);
controller.enqueue(`data: ${JSON.stringify(event)}\n\n`);
}
} catch (error) {
console.error("Error in Prisma stream:", error);
controller.error(error);
}
}

main();
},
cancel() {
console.log("Stream cancelled");
},
});

return new Response(stream, {
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
Connection: "keep-alive",
"Access-Control-Allow-Origin": "*",
},
});
}
//api/+server.js
import { prisma } from "$lib/index.js";

export async function GET({ request }) {
const stream = new ReadableStream({
async start(controller) {
async function main() {
try {
const prismaStream = await prisma.links.stream();

for await (const event of prismaStream) {
console.log("Received event:", event);
controller.enqueue(`data: ${JSON.stringify(event)}\n\n`);
}
} catch (error) {
console.error("Error in Prisma stream:", error);
controller.error(error);
}
}

main();
},
cancel() {
console.log("Stream cancelled");
},
});

return new Response(stream, {
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
Connection: "keep-alive",
"Access-Control-Allow-Origin": "*",
},
});
}
// lib/index.js
import { PrismaClient } from "@prisma/client";
import { withPulse } from "@prisma/extension-pulse";
import { PULSE_API_KEY } from "$env/static/private";

if (!PULSE_API_KEY) {
throw new Error("PULSE_API_KEY environment variable is not set");
}

const prisma = new PrismaClient().$extends(
withPulse({
apiKey: PULSE_API_KEY,
// Add retry options for better reliability
retry: {
maxRetries: 3,
initialDelay: 1000, // 1 second
},
})
);

export { prisma };
// lib/index.js
import { PrismaClient } from "@prisma/client";
import { withPulse } from "@prisma/extension-pulse";
import { PULSE_API_KEY } from "$env/static/private";

if (!PULSE_API_KEY) {
throw new Error("PULSE_API_KEY environment variable is not set");
}

const prisma = new PrismaClient().$extends(
withPulse({
apiKey: PULSE_API_KEY,
// Add retry options for better reliability
retry: {
maxRetries: 3,
initialDelay: 1000, // 1 second
},
})
);

export { prisma };
3 replies
PPrisma
Created by adam boukhris on 6/8/2024 in #help-and-questions
problem when deploying prisma
hello guys , i just completed my portfolio and i'm trying to deploy my app to vercel but i'm always having this error You can mark the path "mock-aws-s3" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time. , the problem is i never used the path that he is talking about , i started getting the error when i added prisma to my code , any idea how to solve it ?
8 replies
PPrisma
Created by adam boukhris on 6/7/2024 in #help-and-questions
problem when deploying
hello guys , i just completed my portfolio and i'm trying to deploy my app to vercel but i'm always having this error You can mark the path "mock-aws-s3" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time. , the problem is i never used the path that he is talking about , i started getting the error when i added prisma to my code , any idea how to solve it ?
2 replies