File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"use server" ;
22
3- import { PrismaClient } from "@prisma/client" ;
4- import { PrismaNeon } from "@prisma/adapter-neon" ;
5- import { Pool } from "@neondatabase/serverless" ;
6- import { notFound } from "next/navigation" ;
7- import Together from "together-ai" ;
3+ import { getPrisma } from "@/lib/prisma" ;
84import {
95 getMainCodingPrompt ,
106 screenshotToCodePrompt ,
117 softwareArchitectPrompt ,
128} from "@/lib/prompts" ;
9+ import { notFound } from "next/navigation" ;
10+ import Together from "together-ai" ;
1311
1412export async function createChat (
1513 prompt : string ,
1614 model : string ,
1715 quality : "high" | "low" ,
1816 screenshotUrl : string | undefined ,
1917) {
20- const neon = new Pool ( { connectionString : process . env . DATABASE_URL } ) ;
21- const adapter = new PrismaNeon ( neon ) ;
22- const prisma = new PrismaClient ( { adapter } ) ;
18+ const prisma = getPrisma ( ) ;
2319 let chat ;
2420 try {
2521 chat = await prisma . chat . create ( {
@@ -195,9 +191,7 @@ export async function createMessage(
195191 text : string ,
196192 role : "assistant" | "user" ,
197193) {
198- const neon = new Pool ( { connectionString : process . env . DATABASE_URL } ) ;
199- const adapter = new PrismaNeon ( neon ) ;
200- const prisma = new PrismaClient ( { adapter } ) ;
194+ const prisma = getPrisma ( ) ;
201195 const chat = await prisma . chat . findUnique ( {
202196 where : { id : chatId } ,
203197 include : { messages : true } ,
Original file line number Diff line number Diff line change @@ -43,11 +43,8 @@ export default function ChatBox({
4343 < div className = "mx-auto mb-5 flex w-full max-w-prose shrink-0 px-8" >
4444 < form
4545 className = "relative flex w-full"
46- action = { async ( formData ) => {
46+ action = { async ( ) => {
4747 startTransition ( async ( ) => {
48- const prompt = formData . get ( "prompt" ) ;
49- assert . ok ( typeof prompt === "string" ) ;
50-
5148 const message = await createMessage ( chat . id , prompt , "user" ) ;
5249 const streamPromise = fetch (
5350 "/api/get-next-completion-stream-promise" ,
@@ -66,7 +63,10 @@ export default function ChatBox({
6663 } ) ;
6764
6865 onNewStreamPromise ( streamPromise ) ;
69- router . refresh ( ) ;
66+ startTransition ( ( ) => {
67+ router . refresh ( ) ;
68+ setPrompt ( "" ) ;
69+ } ) ;
7070 } ) ;
7171 } }
7272 >
Original file line number Diff line number Diff line change 11// import client from "@/lib/prisma";
2- import PageClient from "./page.client " ;
2+ import { getPrisma } from "@/lib/prisma " ;
33import { notFound } from "next/navigation" ;
44import { cache } from "react" ;
5- import { PrismaClient } from "@prisma/client" ;
6- import { PrismaNeon } from "@prisma/adapter-neon" ;
7- import { Pool } from "@neondatabase/serverless" ;
5+ import PageClient from "./page.client" ;
86
97export default async function Page ( {
108 params,
@@ -20,9 +18,7 @@ export default async function Page({
2018}
2119
2220const getChatById = cache ( async ( id : string ) => {
23- const neon = new Pool ( { connectionString : process . env . DATABASE_URL } ) ;
24- const adapter = new PrismaNeon ( neon ) ;
25- const prisma = new PrismaClient ( { adapter } ) ;
21+ const prisma = getPrisma ( ) ;
2622 return await prisma . chat . findFirst ( {
2723 where : { id } ,
2824 include : { messages : { orderBy : { position : "asc" } } } ,
Original file line number Diff line number Diff line change 11import { notFound } from "next/navigation" ;
2- import client from "@/lib/prisma" ;
32import type { Metadata } from "next" ;
43import { cache } from "react" ;
54import CodeRunner from "@/components/code-runner" ;
5+ import { getPrisma } from "@/lib/prisma" ;
66
77/*
88 This is the Share page for v1 apps, before the chat interface was added.
@@ -63,7 +63,8 @@ export default async function Page({
6363}
6464
6565const getGeneratedAppByID = cache ( async ( id : string ) => {
66- return client . generatedApp . findUnique ( {
66+ const prisma = getPrisma ( ) ;
67+ return prisma . generatedApp . findUnique ( {
6768 where : {
6869 id,
6970 } ,
Original file line number Diff line number Diff line change 11/* eslint-disable @next/next/no-img-element */
2+ import { getPrisma } from "@/lib/prisma" ;
23import { ImageResponse } from "next/og" ;
34import { readFile } from "node:fs/promises" ;
45import { join } from "node:path" ;
5- import client from "@/lib/prisma" ;
66
77export const size = {
88 width : 1200 ,
@@ -17,7 +17,8 @@ export default async function Image({
1717 params : { messageId : string } ;
1818} ) {
1919 let messageId = params . messageId ;
20- let message = await client . message . findUnique ( {
20+ const prisma = getPrisma ( ) ;
21+ let message = await prisma . message . findUnique ( {
2122 where : {
2223 id : messageId ,
2324 } ,
Original file line number Diff line number Diff line change 11import CodeRunner from "@/components/code-runner" ;
2- import client from "@/lib/prisma" ;
2+ import { getPrisma } from "@/lib/prisma" ;
33import { extractFirstCodeBlock } from "@/lib/utils" ;
44import { Metadata } from "next" ;
55import { notFound } from "next/navigation" ;
@@ -41,7 +41,8 @@ export default async function SharePage({
4141} ) {
4242 const { messageId } = await params ;
4343
44- const message = await client . message . findUnique ( { where : { id : messageId } } ) ;
44+ const prisma = getPrisma ( ) ;
45+ const message = await prisma . message . findUnique ( { where : { id : messageId } } ) ;
4546 if ( ! message ) {
4647 notFound ( ) ;
4748 }
@@ -59,7 +60,8 @@ export default async function SharePage({
5960}
6061
6162const getMessage = cache ( async ( messageId : string ) => {
62- return client . message . findUnique ( {
63+ const prisma = getPrisma ( ) ;
64+ return prisma . message . findUnique ( {
6365 where : {
6466 id : messageId ,
6567 } ,
Original file line number Diff line number Diff line change 11import { PrismaClient } from "@prisma/client" ;
22import { PrismaNeon } from "@prisma/adapter-neon" ;
33import { Pool } from "@neondatabase/serverless" ;
4+ import { cache } from "react" ;
45
5- declare global {
6- var prisma : PrismaClient | undefined ;
7- }
8-
9- const neon = new Pool ( { connectionString : process . env . DATABASE_URL } ) ;
10- const adapter = new PrismaNeon ( neon ) ;
11-
12- let client : PrismaClient ;
13-
14- if ( process . env . NODE_ENV !== "production" ) {
15- client = globalThis . prisma || new PrismaClient ( { adapter } ) ;
16- globalThis . prisma = client ;
17- } else {
18- client = new PrismaClient ( { adapter } ) ;
19- }
20-
21- export default client ;
6+ export const getPrisma = cache ( ( ) => {
7+ const neon = new Pool ( { connectionString : process . env . DATABASE_URL } ) ;
8+ const adapter = new PrismaNeon ( neon ) ;
9+ return new PrismaClient ( { adapter } ) ;
10+ } ) ;
You can’t perform that action at this time.
0 commit comments