mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 15:31:19 +00:00
28 lines
895 B
TypeScript
28 lines
895 B
TypeScript
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 };
|
|
};
|