Eigenschaft 'Benutzer' User 'existiert nicht auf dem Typ' {} '. Nodepgclient; } '.
Typ' dBQuery 'fehlt die folgenden Eigenschaften aus dem Typ' nodepgdatabase ': _, Abfrage, $ mit, $ count und 10 weitere.
Code: Select all
import * as schema from "../core/models/index";
import { Pool } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import { environmentVar } from "./env";
class DatabaseConnection {
private static instance: DatabaseConnection | null = null;
private pool!: Pool;
private db: ReturnType | null = null;
constructor() {
if (DatabaseConnection.instance) {
return DatabaseConnection.instance;
}
if (!environmentVar.DATABASE_URL) {
throw new Error("DATABASE_URL is not defined in the environment.");
}
this.pool = new Pool({
connectionString: environmentVar.DATABASE_URL,
max: 20,
idleTimeoutMillis: 60000 * 5,
connectionTimeoutMillis: 5000,
});
DatabaseConnection.instance = this;
}
getConnection() {
if (!this.db) {
this.db = drizzle(this.pool, { schema });
}
return this.db;
}
async close() {
if (this.pool) {
await this.pool.end();
console.log("Database pool closed.");
}
}
}
const dbInstance = new DatabaseConnection();
export const db = dbInstance.getConnection();
< /code>
Abfragecode < /p>
import { db } from "../../config/database";
import { eq } from "drizzle-orm";
import { users } from "../core/models/index";
async function findUserByPhoneNumber(phoneNumber: string) {
const user = await db.query.users.findFirst({
where: eq(users.phoneNumber, phoneNumber),
});
return user;
}
Fragen:
Warum erkennt TypeScript mein Schema nicht und zeigt einen Fehler, obwohl der Code funktioniert? ORM färbt das Schema richtig? Es gab angemessene Vorschläge in VS Code Autocompletion und funktionierte gut.
 Mobile version