Try drizzle

This commit is contained in:
Jared Palmer 2023-06-02 11:57:44 -04:00
parent 17bfd0cac1
commit c332a1b6f1
10 changed files with 107 additions and 47 deletions

View file

@ -1,14 +1,14 @@
import { NextChatLogo } from "@/components/ui/nextchat-logo";
import { Login } from "@/components/ui/login";
import { NextChatLogo } from "@/components/ui/nextchat-logo";
import { UserMenu } from "@/components/ui/user-menu";
import { prisma } from "@/lib/prisma";
import { type Session } from "@auth/nextjs/types";
import { db, chats } from "@/lib/db/schema";
import { cn } from "@/lib/utils";
import { type Session } from "@auth/nextjs/types";
import { eq } from "drizzle-orm";
import { Plus } from "lucide-react";
import Link from "next/link";
import { unstable_cache } from "next/cache";
import Link from "next/link";
import { SidebarItem } from "./sidebar-item";
import { db } from "@/lib/db/schema";
export interface SidebarProps {
session?: Session;
@ -59,9 +59,16 @@ export function Sidebar({ session, newChat }: SidebarProps) {
Sidebar.displayName = "Sidebar";
async function SidebarList({ session }: { session?: Session }) {
const chats = await (
const results: any[] = await (
await unstable_cache(
() => db.query.chats.findMany({}),
() =>
db.query.chats.findMany({
columns: {
id: true,
title: true,
},
where: eq(chats.userId, session?.user?.email || ""),
}),
// @ts-ignore
[session?.user?.id || ""],
{
@ -70,7 +77,7 @@ async function SidebarList({ session }: { session?: Session }) {
)
)();
return chats.map((c) => (
return results.map((c) => (
<SidebarItem key={c.id} title={c.title} href={`/chat/${c.id}`} id={c.id} />
));
}