Skip to content

Instantly share code, notes, and snippets.

View Gardego5's full-sized avatar

Garrett Davis Gardego5

View GitHub Profile
@Gardego5
Gardego5 / drizzle-sqlite-jsonAgg.ts
Last active March 13, 2024 15:56
DrizzleORM SQLite JsonAgg inference with function overload
import { AnyColumn, InferColumnsDataTypes, SQL, Table, sql } from "drizzle-orm";
export function jsonAgg<T extends Record<string, AnyColumn>>(select: T): SQL<InferColumnsDataTypes<T>[]>;
export function jsonAgg<T extends Table>(select: T): SQL<T["$inferSelect"][]>;
export function jsonAgg<T extends Record<string, AnyColumn> | Table>(select: T) {
const chunks: SQL[] = [];
var notNullColumn;
Object.entries(select).forEach(([key, column], index) => {
if (index > 0) {