AdaptersPrisma

Prisma

Installation

Make sure you have installed and configured Prisma before using this adapter.

Install package

npm i @uplo/adapter-prisma dataloader

Add adapter to Uplo

import PrismaAdapter from '@uplo/adapter-prisma';
 
const uplo = Uplo({
  adapter: new PrismaAdapter({ prisma }),
})

Prisma Schema

Define Prisma schema with following models. You can change this schema if you use Integer as ID.

FileBlob has all the information about the file and FileAttachment connects a blob to a specific record. You can attach the same file (Blob) with multiple records if needed to save cloud storage space.

datasource db {
  url      = env("DATABASE_URL")
  provider = "postgresql"
}
 
generator client {
  provider = "prisma-client-js"
}
 
model FileAttachment {
  id         String   @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  name       String   @db.VarChar
  recordType String   @db.VarChar
  recordId   String   @db.Uuid
  blobId     String   @db.Uuid
  createdAt  DateTime @default(now()) @db.Timestamptz(6)
 
  blob       FileBlob @relation(fields: [blobId], references: [id])
 
  @@unique([recordType, recordId, name, blobId])
  @@index([recordType, recordId, name])
  @@index([blobId])
}
 
model FileBlob {
  id            String           @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  serviceName   String           @db.VarChar
  key           String           @unique @db.VarChar
  fileName      String           @db.VarChar
  contentType   String?          @db.VarChar
  size          BigInt
  checksum      String           @db.VarChar
  metadata      Json             @default("{}")
  createdAt     DateTime         @default(now()) @db.Timestamptz(6)
 
  attachments   FileAttachment[]
}