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
@@ -0,0 +1,27 @@
import { Knex } from "knex";
import { TDbClient } from "@app/db";
import { TableName,TGitAppInstallSessionsInsert } from "@app/db/schemas";
import { DatabaseError } from "@app/lib/errors";
import { ormify } from "@app/lib/knex";
export type TGitAppInstallSessionDALFactory = ReturnType<typeof gitAppInstallSessionDALFactory>;
export const gitAppInstallSessionDALFactory = (db: TDbClient) => {
const gitAppInstallSessionOrm = ormify(db, TableName.GitAppInstallSession);
const upsert = async (data: TGitAppInstallSessionsInsert, tx?: Knex) => {
try {
const [doc] = await (tx || db)(TableName.GitAppInstallSession)
.insert(data)
.onConflict("orgId")
.merge()
.returning("*");
return doc;
} catch (error) {
throw new DatabaseError({ error, name: "UpsertGitAppOrm" });
}
};
return { ...gitAppInstallSessionOrm, upsert };
};