// --- File: server/db.ts (Mocked Version) --- // This version mocks the database connection to allow the server to start // without a real DATABASE_URL. Actual database operations will not work // and will use these mock implementations. // Original imports are commented out as we are not connecting to a real database. // import { Pool, neonConfig } from '@neondatabase/serverless'; // import { drizzle } from 'drizzle-orm/neon-serverless'; // import ws from "ws"; import * as schema from "@shared/schema"; // Keep schema if other parts of server code might use its types for defining data structures. // neonConfig.webSocketConstructor = ws; // Not needed for mock // The check for DATABASE_URL is removed. /* if (!process.env.DATABASE_URL) { throw new Error( "DATABASE_URL must be set. Did you forget to provision a database?", ); } */ // Original pool and db exports are commented out. /* export const pool = new Pool({ connectionString: process.env.DATABASE_URL }); export const db = drizzle({ client: pool, schema }); */ // --- NEW MOCK IMPLEMENTATION --- console.warn( "INFO: server/db.ts - DATABASE_URL is not configured or this is a mock setup. " + "Running in no-database mode. Database operations will be non-functional or mocked." ); // Mock for 'db'. This needs to be expanded if your application calls more Drizzle methods. // Using 'as any' to simplify typing for this mock during this troubleshooting phase. export const db = { // Mocking a 'select from where' chain select: (..._args: any[]) => { console.warn("MOCK DB: db.select() called."); return { from: (_table: any) => { console.warn("MOCK DB: db.select().from() called."); return { where: async (_condition?: any) => { console.warn("MOCK DB: db.select().from().where() called. Returning empty array."); return []; }, // Add other common chainable methods if used, e.g., limit, offset, orderBy // Mocking common Drizzle execution patterns: execute: async () => { console.warn("MOCK DB: db.select().from().execute() called. Returning empty array."); return []; }, findMany: async (_condition?: any) => { console.warn("MOCK DB: db.select().from().findMany() called. Returning empty array."); return []; }, findOne: async (_condition?: any) => { console.warn("MOCK DB: db.select().from().findOne() called. Returning undefined."); return undefined; } }; }, }; }, // Mocking an 'insert into values' chain insert: (..._args: any[]) => { console.warn("MOCK DB: db.insert() called."); return { into: (_table: any) => { console.warn("MOCK DB: db.insert().into() called."); return { values: async (_data: any) => { console.warn("MOCK DB: db.insert().into().values() called. Returning mock result."); return { affectedRows: 0, insertId: null, rows: [] }; // Drizzle often returns rows/returning }, execute: async () => { console.warn("MOCK DB: db.insert().into().execute() called. Returning mock result."); return { affectedRows: 0, insertId: null, rows: [] }; }, returning: async () => { // if .returning() is used console.warn("MOCK DB: db.insert().into().returning() called. Returning empty array."); return []; } }; }, }; }, // Add basic mocks for other common top-level Drizzle methods if your app uses them directly. // For example, if you use db.query.yourTable.findMany(): query: new Proxy({}, { get: function(_target, prop_table) { console.warn(`MOCK DB: db.query.${String(prop_table)} accessed.`); return new Proxy({}, { get: function(_target_table, prop_method) { console.warn(`MOCK DB: db.query.${String(prop_table)}.${String(prop_method)}() called.`); return async (..._args: any[]) => { console.warn(`MOCK DB: db.query.${String(prop_table)}.${String(prop_method)}() executing. Returning empty array/undefined based on method.`); if (String(prop_method).includes('findMany')) return []; if (String(prop_method).includes('findOne')) return undefined; return []; // Default empty array }; } }); } }), // Add update, delete, etc., as needed, following a similar pattern. // e.g. db.update(...).set(...).where(...).execute() / .returning() update: (..._args: any[]) => { console.warn("MOCK DB: db.update() called."); return { set: (_data: any) => ({ where: async (_condition?: any) => { console.warn("MOCK DB: db.update().set().where() called. Returning mock result."); return { affectedRows: 0, rows: [] }; }, execute: async () => { console.warn("MOCK DB: db.update().set().execute() called. Returning mock result."); return { affectedRows: 0, rows: [] }; }, returning: async () => { console.warn("MOCK DB: db.update().set().returning() called. Returning empty array."); return []; } }) }; }, delete: (..._args: any[]) => { console.warn("MOCK DB: db.delete() called."); return { from: (_table: any) => ({ // Drizzle's delete is often `db.delete(tables.users).where(...)` where: async (_condition?: any) => { console.warn("MOCK DB: db.delete().where() called. Returning mock result."); return { affectedRows: 0 }; }, execute: async () => { console.warn("MOCK DB: db.delete().execute() called. Returning mock result."); return { affectedRows: 0 }; }, returning: async () => { console.warn("MOCK DB: db.delete().returning() called. Returning empty array."); return []; } }), }; } } as any; // Using 'as any' to avoid needing to mock every single Drizzle method exhaustively. // Mock for 'pool' if it's used directly anywhere (less common with Drizzle ORM). export const pool = { connect: async () => { console.warn("MOCK DB: pool.connect called."); return { query: async (_sql: string, _params?: any[]) => { console.warn("MOCK DB: pool.query called. Returning empty result."); return { rows: [], rowCount: 0 }; }, release: () => { console.warn("MOCK DB: pool.release called."); }, }; }, // Add other methods if your 'pool' object is used for more. } as any; // Using 'as any' for simplicity. // The schema import is kept because other parts of your application might // use the TypeScript types defined in your Drizzle schema (e.g., for API request/response bodies), // even if you're not actually querying the database. // If you are certain no other server file uses types from the schema, you could comment out // the `import * as schema from "@shared/schema";` line, but it's generally safer to keep it. // This also makes the `drizzle({ client: pool, schema })` line happy if it were not commented. export { schema }; // Re-export schema if it was imported, so other files can still get it