Skip to main content

durcno@1.0.0-alpha.18

Minor Changes​

  • fe4d888 - Thanks to @almahdi404 !

    feat(select): add groupBy and having clauses

    SelectQuery now supports explicit GROUP BY and HAVING clauses via .groupBy() and .having() methods.

    .groupBy() accepts a column, a scalar SqlFn, or an array of either. It also supports a callback form that lets you reference named aliases from your .select({...}) map — useful when grouping by computed expressions.

    .having() filters grouped results using aggregate expressions. Comparison filters (eq, ne, gt, gte, lt, lte) were extended to accept aggregate SqlFn operands, enabling aggregate-to-literal and aggregate-to-aggregate comparisons.

    // Direct form
    const result = await db
    .from(Users)
    .select({ type: Users.type, total: count("*") })
    .groupBy(Users.type)
    .having(gte(count("*"), 5));

    // Callback form — reference select aliases
    const result2 = await db
    .from(Users)
    .select({ lname: lower(Users.username), total: count("*") })
    .groupBy(({ lname }) => [lname]);

    Both methods are one-time — calling .groupBy() or .having() a second time is a compile-time error. Aggregate functions are rejected by the type system as GROUP BY operands (only scalar expressions and columns are valid).

Patch Changes​

  • f99cb38 - Thanks to @almahdi404 !

    fix(rq/types): use explicit return type in .findFirst

    Use an explicit return type for findFirst in RelationQueryBuilder so nested relation queries preserve their inferred result shape. Added a type-level annotation and coverage for a 3-level nested relation query (Posts → comments → author).

  • 2bedca0 - Thanks to @almahdi404 !

    fix(migration/ddl): extract DDLStatement to break recursive import

    DDLStatement, DDLStatementType, CustomStatement, and custom were previously defined directly in src/migration/ddl/index.ts. Since other DDL modules (schema.ts, table.ts, types.ts, indexes.ts, sequence.ts) all imported DDLStatement from ./index, this created a recursive import cycle.

    The fix extracts these base definitions into a new dedicated file src/migration/ddl/statement.ts. All DDL modules now import DDLStatement from ./statement, and index.ts re-exports everything from statement.ts — eliminating the circular dependency.