mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49: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
|
|
@ -10,7 +10,6 @@ import {
|
|||
type InferInsertModel,
|
||||
type InferSelectModel,
|
||||
type SQL,
|
||||
count,
|
||||
desc,
|
||||
eq,
|
||||
inArray,
|
||||
|
|
@ -340,13 +339,7 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
});
|
||||
}
|
||||
|
||||
static async getCount() {
|
||||
return (
|
||||
await db
|
||||
.select({
|
||||
count: count(),
|
||||
})
|
||||
.from(Instances)
|
||||
)[0].count;
|
||||
static getCount(): Promise<number> {
|
||||
return db.$count(Instances);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import {
|
|||
type InferInsertModel,
|
||||
type SQL,
|
||||
and,
|
||||
count,
|
||||
desc,
|
||||
eq,
|
||||
inArray,
|
||||
|
|
@ -349,16 +348,10 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
|||
* @returns The number of notes in the database
|
||||
*/
|
||||
static async getCount(): Promise<number> {
|
||||
return (
|
||||
await db
|
||||
.select({
|
||||
count: count(),
|
||||
})
|
||||
.from(Notes)
|
||||
.where(
|
||||
sql`EXISTS (SELECT 1 FROM "Users" WHERE "Users"."id" = ${Notes.authorId} AND "Users"."instanceId" IS NULL)`,
|
||||
)
|
||||
)[0].count;
|
||||
return await db.$count(
|
||||
Notes,
|
||||
sql`EXISTS (SELECT 1 FROM "Users" WHERE "Users"."id" = ${Notes.authorId} AND "Users"."instanceId" IS NULL)`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import {
|
|||
type InferInsertModel,
|
||||
type SQL,
|
||||
and,
|
||||
count,
|
||||
countDistinct,
|
||||
desc,
|
||||
eq,
|
||||
|
|
@ -327,15 +326,8 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
);
|
||||
}
|
||||
|
||||
static async getCount() {
|
||||
return (
|
||||
await db
|
||||
.select({
|
||||
count: count(),
|
||||
})
|
||||
.from(Users)
|
||||
.where(isNull(Users.instanceId))
|
||||
)[0].count;
|
||||
static getCount(): Promise<number> {
|
||||
return db.$count(Users, isNull(Users.instanceId));
|
||||
}
|
||||
|
||||
static async getActiveInPeriod(milliseconds: number) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue