-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdatabase.ts
More file actions
30 lines (25 loc) · 875 Bytes
/
database.ts
File metadata and controls
30 lines (25 loc) · 875 Bytes
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
import { Env } from "@/core/utils/env.ts";
import { MongoClient, MongoError, MongoServerError } from "mongodb";
export const mongodb = new MongoClient(Env.getSync("DATABASE_URL"), {
maxPoolSize: 30,
waitQueueTimeoutMS: 10000,
});
export function hasMongoErrorLabel(
error: unknown,
label: string,
): boolean {
return (
error instanceof MongoError &&
typeof error.hasErrorLabel === "function" &&
error.hasErrorLabel(label)
);
}
export function isTransientTransactionError(error: unknown): boolean {
return hasMongoErrorLabel(error, "TransientTransactionError");
}
export function isUnknownTransactionCommitResult(error: unknown): boolean {
return hasMongoErrorLabel(error, "UnknownTransactionCommitResult");
}
export function isDuplicateKeyError(error: unknown): boolean {
return error instanceof MongoServerError && error.code === 11000;
}