2024-03-17 12:58:25 +01:00
|
|
|
import { PostgresDialect } from "kysely";
|
|
|
|
|
import { Pool } from "pg";
|
|
|
|
|
import { KyselyAuth } from "@auth/kysely-adapter";
|
|
|
|
|
import { CamelCasePlugin } from "kysely";
|
|
|
|
|
import type { GeneratedAlways } from "kysely";
|
|
|
|
|
|
|
|
|
|
interface Database {
|
|
|
|
|
User: {
|
2024-03-20 17:51:21 +01:00
|
|
|
id: string;
|
2024-03-17 12:58:25 +01:00
|
|
|
name: string | null;
|
|
|
|
|
email: string;
|
|
|
|
|
emailVerified: Date | null;
|
|
|
|
|
image: string | null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Account: {
|
|
|
|
|
id: GeneratedAlways<string>;
|
|
|
|
|
userId: string;
|
2024-03-20 17:51:21 +01:00
|
|
|
type: "oidc" | "oauth" | "email" | "webauthn";
|
2024-03-17 12:58:25 +01:00
|
|
|
provider: string;
|
|
|
|
|
providerAccountId: string;
|
2024-03-20 17:51:21 +01:00
|
|
|
refresh_token: string | undefined;
|
|
|
|
|
access_token: string | undefined;
|
|
|
|
|
expires_at: number | undefined;
|
|
|
|
|
token_type: Lowercase<string> | undefined;
|
|
|
|
|
scope: string | undefined;
|
|
|
|
|
id_token: string | undefined;
|
|
|
|
|
session_state: string | undefined;
|
2024-03-17 12:58:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Session: {
|
|
|
|
|
id: GeneratedAlways<string>;
|
|
|
|
|
userId: string;
|
|
|
|
|
sessionToken: string;
|
|
|
|
|
expires: Date;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VerificationToken: {
|
|
|
|
|
identifier: string;
|
|
|
|
|
token: string;
|
|
|
|
|
expires: Date;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WhatsAppBot: {
|
|
|
|
|
id: GeneratedAlways<string>;
|
|
|
|
|
userId: string;
|
|
|
|
|
phone: string;
|
|
|
|
|
password: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const db = new KyselyAuth<Database>({
|
|
|
|
|
dialect: new PostgresDialect({
|
|
|
|
|
pool: new Pool({
|
|
|
|
|
host: process.env.DATABASE_HOST,
|
|
|
|
|
database: process.env.DATABASE_NAME,
|
|
|
|
|
user: process.env.DATABASE_USER,
|
|
|
|
|
password: process.env.DATABASE_PASSWORD,
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
plugins: [new CamelCasePlugin()],
|
|
|
|
|
});
|