Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat: prisma store) and (fix: setting store in NextUpload) #55

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ yarn.lock
*.ico
**/.next/**
README.md
*.sql
*.sql
schema.prisma
6 changes: 4 additions & 2 deletions examples/next-upload-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
"dependencies": {
"@keyv/postgres": "^1.4.10",
"@neondatabase/serverless": "^0.9.0",
"@prisma/adapter-neon": "^5.12.1",
"@prisma/client": "^5.12.1",
"@types/node": "20.12.7",
"@types/react": "18.2.78",
"@types/react-dom": "18.2.25",
"bytes": "^3.1.2",
"drizzle-orm": "^0.30.8",
"eslint": "9.0.0",
"eslint": "^8.0.0",
"eslint-config-next": "14.2.1",
"keyv": "^4.5.4",
"next": "14.2.1",
"next-upload": "^0.0.30",
"postgres": "^3.4.4",
"prisma": "^5.12.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
Expand Down
4 changes: 4 additions & 0 deletions examples/next-upload-example/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default async function Home() {
api="/upload/edge-with-drizzle-neon"
title="Edge upload with Drizzle Neon Serverless Postgres store "
/>
<FileUpload
api="/upload/prisma"
title="Edge upload with Prisma store "
/>
</div>
</main>
);
Expand Down
10 changes: 10 additions & 0 deletions examples/next-upload-example/src/app/upload/prisma/nup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NextUpload } from 'next-upload';
import { NextUploadPrismaStore } from 'next-upload/store/prisma';

import { nextUploadConfig } from '@/app/nextUploadConfig';
import { prisma } from '@/prisma/client';

export const nup = new NextUpload(
nextUploadConfig,
new NextUploadPrismaStore(prisma)
);
10 changes: 10 additions & 0 deletions examples/next-upload-example/src/app/upload/prisma/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NextRequest } from 'next/server';

import { nup } from './nup';

export const POST = (request: NextRequest) => nup.handler(request);

export const dynamic = 'force-dynamic';

// Optionally, if your application supports it you can run next-upload in the Edge runtime.
export const runtime = 'edge';
13 changes: 13 additions & 0 deletions examples/next-upload-example/src/prisma/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PrismaClient } from '@prisma/client';
import { PrismaNeon } from '@prisma/adapter-neon';
import { Pool } from '@neondatabase/serverless';

const neon = new Pool({ connectionString: process.env.POSTGRES_PRISMA_URL });
const adapter = new PrismaNeon(neon);

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
export const prisma = globalForPrisma.prisma || new PrismaClient({ adapter });

if (process.env.NODE_ENV !== 'production') {
globalForPrisma.prisma = prisma;
}
22 changes: 22 additions & 0 deletions examples/next-upload-example/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}

model NextUploadAsset {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
data Json
expires BigInt?
presignedUrl String?
presignedUrlExpires BigInt?

@@map("next_upload_assets")
}
Loading