X
Xata4mo ago
dream

Using prisma to create a new record with a file column

How do I use the prisma client to create a new record with an empty file column? I've tried the following: 1. Placeholder metadata (taking hints from this example: https://xata.io/docs/sdk/file-attachments#1-createupdate-a-record-with-an-empty-file-server-side)
await prisma.message.create({
data: {
conversationId,
userMessage,
botMessage,
image: { name: 'test', mediaType: 'image/png', base64Content: '' },
},
})
await prisma.message.create({
data: {
conversationId,
userMessage,
botMessage,
image: { name: 'test', mediaType: 'image/png', base64Content: '' },
},
})
2. Empty object:
await prisma.message.create({
data: {
conversationId,
userMessage,
botMessage,
image: {},
},
})
await prisma.message.create({
data: {
conversationId,
userMessage,
botMessage,
image: {},
},
})
For each case I get the error:
Can't reach database server at `us-east-1.sql.xata.sh:5432
Can't reach database server at `us-east-1.sql.xata.sh:5432
What is the correct format?
3 Replies
dream
dreamOP4mo ago
@kostas Please help?
kostas
kostas4mo ago
Hi, File columns are a Xata-specific type and only work over the REST API. You cannot read/write to them properly via Prisma unfortunately. You'll need to use the Xata TS SDK to interface with File/File[] columns. Prisma cannot write to them in the proper format. There is an intermediate service sitting between Postgres and the REST API that manages File column metadata, urls, content validation etc. Prisma talks to Postgres directly, which isn't the appropriate endpoint for Files. We're actively working to make File columns work directly within Postgres, there is a refactoring in progress. In the meantime, File columns should only be touched by the TS SDK.
dream
dreamOP4mo ago
Okay, that's great to know. Thanks for the explanation!
Want results from more Discord servers?
Add your server