fix: use getRawDb() instead of drizzle $client for explore tab
$client doesn't exist in drizzle-orm 0.33, causing a TypeError and 500 on every /api/servers/explore request. Export the raw better-sqlite3 instance directly from db/index.ts instead.
This commit is contained in:
@@ -226,6 +226,10 @@ export function getDb(): DB {
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRawDb(): Database.Database {
|
||||||
|
return sqlite;
|
||||||
|
}
|
||||||
|
|
||||||
export function closeDatabase(): void {
|
export function closeDatabase(): void {
|
||||||
if (sqlite) {
|
if (sqlite) {
|
||||||
sqlite.close();
|
sqlite.close();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { FastifyInstance } from 'fastify';
|
import type { FastifyInstance } from 'fastify';
|
||||||
import { eq, and, sql, inArray } from 'drizzle-orm';
|
import { eq, and, sql, inArray } from 'drizzle-orm';
|
||||||
import { getDb, schema } from '../db/index.js';
|
import { getDb, getRawDb, schema } from '../db/index.js';
|
||||||
import { authenticate } from '../utils/auth.js';
|
import { authenticate } from '../utils/auth.js';
|
||||||
import { generateSnowflake } from '../utils/snowflake.js';
|
import { generateSnowflake } from '../utils/snowflake.js';
|
||||||
import { isMember, isServerOwner, hasPermission, computePermissions, PermissionBits, permissionsToString } from '../utils/permissions.js';
|
import { isMember, isServerOwner, hasPermission, computePermissions, PermissionBits, permissionsToString } from '../utils/permissions.js';
|
||||||
@@ -193,7 +193,7 @@ export async function exploreRoutes(app: FastifyInstance): Promise<void> {
|
|||||||
|
|
||||||
// Build raw SQL query for explore — we need a LEFT JOIN for member count
|
// Build raw SQL query for explore — we need a LEFT JOIN for member count
|
||||||
// which is more efficient to do with raw SQL
|
// which is more efficient to do with raw SQL
|
||||||
const rawDb = (db as any).$client as import('better-sqlite3').Database;
|
const rawDb = getRawDb();
|
||||||
|
|
||||||
// Count ALL discoverable servers (including ones the user has joined) for context
|
// Count ALL discoverable servers (including ones the user has joined) for context
|
||||||
const totalAllRow = rawDb.prepare(
|
const totalAllRow = rawDb.prepare(
|
||||||
|
|||||||
Reference in New Issue
Block a user