-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-db.js
More file actions
46 lines (38 loc) Β· 1.19 KB
/
test-db.js
File metadata and controls
46 lines (38 loc) Β· 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require("dotenv").config();
const { PrismaClient } = require("@prisma/client");
const { PrismaPg } = require("@prisma/adapter-pg");
const pg = require("pg");
console.log("π Testing Prisma with adapter...");
console.log("DATABASE_URL:", process.env.DATABASE_URL);
const pool = new pg.Pool({
connectionString: process.env.DATABASE_URL,
ssl: false,
connectionTimeoutMillis: 5000,
max: 5,
});
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({
adapter,
log: ["query", "error", "warn"],
});
async function test() {
try {
console.log("π Connecting to Prisma...");
await prisma.$connect();
console.log("β
Prisma connected");
console.log("π Running query...");
const result = await prisma.$queryRaw`SELECT 1 as test`;
console.log("β
Query result:", result);
console.log("π Finding users...");
const users = await prisma.user.findMany({ take: 1 });
console.log("β
Users count:", users.length);
await prisma.$disconnect();
console.log("β
Test complete");
process.exit(0);
} catch (error) {
console.error("β Error:", error.message);
console.error("Stack:", error.stack);
process.exit(1);
}
}
test();