-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
66 lines (52 loc) · 1.33 KB
/
Copy pathmain.ts
File metadata and controls
66 lines (52 loc) · 1.33 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Prisma, PrismaClient } from '.prisma/client'
import { Pool } from "pg";
import { PrismaPg } from "@prisma/adapter-pg";
const connectionString = `${process.env.DATABASE_URL as string}`;
const pool = new Pool({ connectionString });
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({
adapter,
log: ["query"],
});
const id = "a0eeea10-7911-4af2-0000-01400b5718d2";
const intId = BigInt(1374511782084);
async function populate() {
await prisma.user.create({
data: {
id,
intId,
name: "Christopher Addison",
}
});
await prisma.baseUser.create({
data: {
id,
intId,
}
});
}
type User = Prisma.BaseUserGetPayload<{ include: { user: true } }>
async function getUnsafe(id: string | bigint): Promise<User | null> {
const query = {
where: typeof id === "bigint" ? { intId: id } : { id },
include: { user: true },
};
const result = await prisma.baseUser.findUnique(query);
if (!result) {
return null;
}
return result;
}
async function test() {
const u = await getUnsafe(id);
console.log(u);
}
async function main() {
await populate();
return test();
}
main()
.catch((e) => console.error(e))
.finally(async () => {
prisma.$disconnect();
});