diff --git a/src/idz/db/_util.ts b/src/idz/db/_util.ts new file mode 100644 index 0000000..6be4494 --- /dev/null +++ b/src/idz/db/_util.ts @@ -0,0 +1,25 @@ +import * as sql from "sql-bricks"; +import { Client } from "pg"; + +import { ExtId } from "../model/base"; +import { Profile } from "../model/profile"; +import { Id } from "../../db"; + +export async function _findProfile( + conn: Client, + extId: ExtId +): Promise | undefined> { + const lookupSql = sql + .select("r.id") + .from("idz.profile r") + .where("r.ext_id", extId) + .toParams(); + + const { rows } = await conn.query(lookupSql); + + if (rows.length > 0) { + return rows[0].id as Id; + } else { + throw new Error("Profile not found"); + } +}