Updated lib

This commit is contained in:
2025-06-26 23:27:06 +02:00
parent 3bd9a73760
commit 6a8b2b9e2e
2 changed files with 9 additions and 2 deletions

View File

@@ -29,6 +29,7 @@ import { Input } from "@/components/ui/input"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { deleteUrl } from "@/lib/actions/url" import { deleteUrl } from "@/lib/actions/url"
import { urls } from "@/lib/drizzle/schema" import { urls } from "@/lib/drizzle/schema"
import Link from "next/link"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { toast } from "sonner" import { toast } from "sonner"
@@ -67,7 +68,9 @@ export const columns: ColumnDef<UrlRecord>[] = [
const url = row.getValue("url") as string const url = row.getValue("url") as string
return ( return (
<div className="max-w-[300px] truncate" title={url}> <div className="max-w-[300px] truncate" title={url}>
{url} <Link href={url}>
{url.replace(/^(https?:\/\/)/, "")}
</Link>
</div> </div>
) )
} }

View File

@@ -1,4 +1,4 @@
import { eq, desc } from "drizzle-orm"; import { eq, desc, count } from "drizzle-orm";
import { db } from "../drizzle/db"; import { db } from "../drizzle/db";
import { urls, visits } from "../drizzle/schema"; import { urls, visits } from "../drizzle/schema";
@@ -14,6 +14,10 @@ export function getUrlBySlug(slug: string) {
}) })
} }
export function getVisitsBySlugById(id: string) {
return db.select({ count: count() }).from(visits).where(eq(visits.urlId, id))
}
export function insertUrl(data: typeof urls.$inferInsert) { export function insertUrl(data: typeof urls.$inferInsert) {
return db.insert(urls).values(data) return db.insert(urls).values(data)
} }