Updated lib
This commit is contained in:
@@ -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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user