Alexcitten
Alexcitten
Explore posts from servers
PPrisma
Created by Alexcitten on 7/7/2024 in #help-and-questions
Can't reach database server at localhost:5432
PostgreSQL 16, I'm implementing OpenAPI on Cloudfare Workers using TypeScript, I did an endpoint and it shows an error PrismaClientKnownRequestError: Invalid prisma.clientProfile.create() invocation: This request could not be understood by the server: {"type":"UnknownJsonError","body":{"code":"P6008","message":"Accelerate was not able to connect to your database. The underlying error is: Can't reach database server at localhost:5432\n\nPlease make sure your database server is running at localhost:5432."}} I don't understand what the error is because my seeding is working correctly, the whole database setup seems to be correct, next I will give more input from my app Endpoint:
import prisma from '../../prisma/prisma';
...
async handle(request: Request, env: any, context: any, data: Record<string, any>) {
const profileToCreate = data.body;

try {
const createdProfile = await prisma.clientProfile.create({
data: {
companyName: profileToCreate.companyName,
registeredOffice: profileToCreate.registeredOffice,
uniqueRegistrationCode: profileToCreate.uniqueRegistrationCode,
commercialRegisterNumber: profileToCreate.commercialRegisterNumber,
billingEmails: profileToCreate.billingEmails,
contactDetails: {
create: profileToCreate.contactDetails.map((contact: any) => ({
contactPerson: contact.contactPerson,
contactEmail: contact.contactEmail,
contactPhone: contact.contactPhone,
})),
},
},
});

return {
success: true,
result: createdProfile,
};
...
import prisma from '../../prisma/prisma';
...
async handle(request: Request, env: any, context: any, data: Record<string, any>) {
const profileToCreate = data.body;

try {
const createdProfile = await prisma.clientProfile.create({
data: {
companyName: profileToCreate.companyName,
registeredOffice: profileToCreate.registeredOffice,
uniqueRegistrationCode: profileToCreate.uniqueRegistrationCode,
commercialRegisterNumber: profileToCreate.commercialRegisterNumber,
billingEmails: profileToCreate.billingEmails,
contactDetails: {
create: profileToCreate.contactDetails.map((contact: any) => ({
contactPerson: contact.contactPerson,
contactEmail: contact.contactEmail,
contactPhone: contact.contactPhone,
})),
},
},
});

return {
success: true,
result: createdProfile,
};
...
schema:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema", "driverAdapters"]
engineType = "library"
}
...
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema", "driverAdapters"]
engineType = "library"
}
...
../../prisma/prisma:
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

const prismaClient = new PrismaClient({
datasources: {
db: {
url: 'prisma://accelerate.prisma-data.net/?api_key=KEY...',
},
},
}).$extends(withAccelerate());

export default prismaClient;
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

const prismaClient = new PrismaClient({
datasources: {
db: {
url: 'prisma://accelerate.prisma-data.net/?api_key=KEY...',
},
},
}).$extends(withAccelerate());

export default prismaClient;
.env: DIRECT_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres?schema=public" DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=apikey" When using endpoint, in my pgAdmin 4 database I see activity from connections, the correct link is connected to my database in Accelerate, but I get this error. my seed.ts, which works just fine:
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
const clientProfiles = [
{
companyName: '...',
registeredOffice: '...',
uniqueRegistrationCode: '...',
commercialRegisterNumber: '...',
billingEmails: ['..'],
contactDetails: {
create: [
{
contactPerson: 'J..',
contactEmail: '..',
contactPhone: '..',
},
{
contactPerson: '..',
contactEmail: '..',
contactPhone: '..',
},
],
},
},
{
companyName: '..',
registeredOffice: '..',
uniqueRegistrationCode: '..,
commercialRegisterNumber: '1.',
billingEmails: ['....', '..'],
contactDetails: {
create: [
{
contactPerson: '..n',
contactEmail: '...m',
contactPhone: '1...',
},
],
},
},
];

for (const clientProfile of clientProfiles) {
await prisma.clientProfile.create({
data: clientProfile,
});
}
...
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
const clientProfiles = [
{
companyName: '...',
registeredOffice: '...',
uniqueRegistrationCode: '...',
commercialRegisterNumber: '...',
billingEmails: ['..'],
contactDetails: {
create: [
{
contactPerson: 'J..',
contactEmail: '..',
contactPhone: '..',
},
{
contactPerson: '..',
contactEmail: '..',
contactPhone: '..',
},
],
},
},
{
companyName: '..',
registeredOffice: '..',
uniqueRegistrationCode: '..,
commercialRegisterNumber: '1.',
billingEmails: ['....', '..'],
contactDetails: {
create: [
{
contactPerson: '..n',
contactEmail: '...m',
contactPhone: '1...',
},
],
},
},
];

for (const clientProfile of clientProfiles) {
await prisma.clientProfile.create({
data: clientProfile,
});
}
...
Open to any discussion, I really want to get this fixed. Thank you!
4 replies