feat: changed backend-pg to backend

This commit is contained in:
Akhil Mohan
2024-01-27 19:14:33 +05:30
parent d13eafcef7
commit 66d258f02b
792 changed files with 40298 additions and 40607 deletions
+30
View File
@@ -0,0 +1,30 @@
import { Knex } from "knex";
import { TDbClient } from "@app/db";
import { TableName, TBackupPrivateKey } from "@app/db/schemas";
import { withTransaction } from "@app/lib/knex";
export type TAuthDALFactory = ReturnType<typeof authDALFactory>;
export const authDALFactory = (db: TDbClient) => {
const getBackupPrivateKeyByUserId = async (userId: string) =>
db(TableName.BackupPrivateKey).where({ userId }).first("*");
const upsertBackupKey = async (
userId: string,
data: Partial<TBackupPrivateKey>,
tx?: Knex
): Promise<TBackupPrivateKey | undefined> => {
const [backupKey] = await (tx || db)(TableName.BackupPrivateKey)
.insert({ userId, ...data, updatedAt: new Date() } as TBackupPrivateKey)
.onConflict("userId")
.merge()
.returning("*");
return backupKey;
};
return withTransaction(db, {
getBackupPrivateKeyByUserId,
upsertBackupKey
});
};