mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
refactor(database): ♻️ Use new Drizzle count API
This commit is contained in:
parent
7f17074d16
commit
ce781f3336
5 changed files with 43 additions and 93 deletions
|
|
@ -4,7 +4,7 @@ import {
|
|||
Collection as CollectionSchema,
|
||||
Note as NoteSchema,
|
||||
} from "@versia/federation/schemas";
|
||||
import { and, count, eq, inArray } from "drizzle-orm";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import { db } from "~/drizzle/db";
|
||||
import { Notes } from "~/drizzle/schema";
|
||||
|
|
@ -102,19 +102,13 @@ export default apiRoute((app) =>
|
|||
NOTES_PER_PAGE * (pageNumber - 1),
|
||||
);
|
||||
|
||||
const totalNotes = (
|
||||
await db
|
||||
.select({
|
||||
count: count(),
|
||||
})
|
||||
.from(Notes)
|
||||
.where(
|
||||
and(
|
||||
eq(Notes.authorId, uuid),
|
||||
inArray(Notes.visibility, ["public", "unlisted"]),
|
||||
),
|
||||
)
|
||||
)[0].count;
|
||||
const totalNotes = await db.$count(
|
||||
Notes,
|
||||
and(
|
||||
eq(Notes.authorId, uuid),
|
||||
inArray(Notes.visibility, ["public", "unlisted"]),
|
||||
),
|
||||
);
|
||||
|
||||
const json = {
|
||||
first: new URL(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue