Using complex JSON functions

We're using AWS Aurora + knex at the moment, and we've got some knex helpers like this:
/**
 * Takes an object and returns a Postgres json_build_object()
 * @param obj A map of any shape
 * @param alias Column alias
 * @returns json_build_object() SQL code
 */
export function jsonBuildObjectSql(
  obj: Record<string, unknown>,
  alias?: string,
  checkFieldForNull?: string
): string {
  return (
    (checkFieldForNull
      ? `case when ${checkFieldForNull} is not null then `
      : '') +
    'json_build_object(' +
    Object.entries(obj)
      .map(pair => [`'${pair[0]}'`, pair[1]])
      .join(', ') +
    ')' +
    (checkFieldForNull ? ' else null end' : '') +
    (alias ? ` as ${alias}` : '')
  );
}

I'd love to move to Supabase, but I'm not sure if the engine is capable of this or not (strictly speaking of @supabase/supabase-js). I'd rather not use actual DB connections, as all of our back-end is in Lambda functions, so the API approach is much neater
Was this page helpful?