Skip to main content

durcno@1.0.0-alpha.34

Major Changes​

  • e955365 - Thanks to @almahdi404 !

    change(query)!: split the join clause into an .on() method

    innerJoin and leftJoin each took the joined table and the ON condition in one call. The condition is now supplied to a separate .on() on the join builder those two methods return.

    // before
    db.from(Users).innerJoin(Posts, () => eq(Users.id, Posts.userId));

    // after
    db.from(Users).innerJoin(Posts).on(() => eq(Users.id, Posts.userId));

    Generated SQL, row decoding, and every inferred type are unchanged — only the call shape moved. To migrate, split each two-argument join at its callback. .on() takes the same callback, so the body is untouched.

    Why​

    .on() is what SQL itself uses, so the builder now reads like the statement it emits: FROM users INNER JOIN posts ON ... instead of a two-argument call that folded the table and its condition together.

    Making that two steps also means a pending join is a distinct type with one method on it, so a join cannot be left half-written — there is no way to reach .select() on a join that never got an ON, and nothing to clean up at runtime.

    It also gives the condition the same callback shape as .select(), .where(), .orderBy(), .groupBy() and .having(), rather than being the one join argument that was a callback and the other three that were not.

    Cost​

    Negligible. Splitting the call adds one small intermediate object per join, which measures in the low tens of nanoseconds — invisible next to the query build it belongs to, and far below the network round-trip that query then costs. A wide multi-join query sees the same per-join figure, not a compounding one.

  • a2f0e3c - Thanks to @almahdi404 !

    fix(functions)!: nested aggregates in select no longer become GROUP BY keys

    A SELECT whose projection contains a nested aggregate — an aggregate wrapped in another function, such as round(avg(rating), 1) — used to treat it as a scalar and put it in GROUP BY, producing aggregate functions are not allowed in GROUP BY. When every projection item is an aggregate, the query now emits no GROUP BY and returns one aggregate row.

    // aggregates only: no GROUP BY, one row
    await db.from(Reviews).select(() => ({
    totalCount: count("*"),
    averageRating: round(avg(Reviews.rating), 1),
    }));

    // a wrapped aggregate beside a plain column: group by the column alone
    await db.from(Reviews).select(() => ({
    productId: Reviews.productId,
    averageRating: round(avg(Reviews.rating), 1),
    }));
    // GROUP BY "reviews"."product_id"

    Clause rules​

    • GROUP BY, WHERE/ON, INSERT/SET values and FILTER (WHERE ...) refuse an aggregate at any nesting depth, at compile time. WHERE now also rejects a bare count("*").
    • HAVING, ORDER BY and grouped CASE WHEN conditions accept one, wrapped or not.
    • ORDER BY only applies when the query aggregates; otherwise PostgreSQL rejects the query itself.
    • An aggregate in a CASE WHEN condition is part of the CASE, not a grouping key; columns read by a plain condition join the auto GROUP BY.

    Also fixed​

    • caseWhen(...) is accepted in .set(); the coalesce(...) workaround is unnecessary.
    • avg(round(sum(x), 2)) is invalid SQL and is now a compile error.
    • having(() => gt(round(avg(x), 1), 2)) and orderBy(() => asc(round(avg(x), 1))) now compile.
    • where(() => gt(round(avg(x), 1), 5)) no longer compiles — it was invalid SQL.
    await db
    .from(Users)
    .select(() => ({ type: Users.type, avgScore: round(avg(Users.score), 1) }))
    .groupBy(() => Users.type)
    .having(() => gt(round(avg(Users.score), 1), 2))
    .orderBy(() => desc(round(avg(Users.score), 1)));

    Performance​

    Aggregate detection walks a function's operands once at construction. The binary constructors call it once per operand instead of allocating a pair — roughly 10–40% faster per call against the pair shape; perf/sqlfn-operands.paths.ts measures it.

    API​

    SqlFn.isAggregate is now SqlFn.hasAggregate, and SqlFn.sqlFnType exposes the function kind ("aggregate" or "scalar").

  • 9aac13c - Thanks to @almahdi404 !

    fix(functions)!: JSON values keep the type of their source column

    PostgreSQL serializes a value into JSON by its own rules — an int8 becomes a number, a timestamptz a string — so a JSON expression used to hand back whatever the driver parsed, even though the inferred type said otherwise. Every JSON and JSONB expression now reads its result back through the expressions that built it, so a value keeps the type of its source column.

    await db.from(Users).select(() => ({
    card: jsonBuildObject({
    id: Users.id, // bigint column -> bigint
    createdAt: Users.createdAt, // timestamptz column -> Date
    }),
    }));
    // card is inferred as { id: bigint; createdAt: Date }

    The restore covers jsonBuildObject, jsonbBuildObject, jsonAgg, jsonbAgg, jsonBuildArray, jsonbBuildArray, toJson, toJsonb, jsonStripNulls and jsonbStripNulls. A literal operand is restored as well — a Date comes back as a Date and a bigint as a bigint.

    An array literal is encoded as a JSON array in every JSON expression — empty, mixed, bigint, and Date arrays included — and its elements are restored to their declared types. toJson/toJsonb also accept scalar string, null, and array targets.

    Breaking​

    • toJson(table) returns the JavaScript column names, the ones its type always promised — createdAt, not created_at.
    • toJson(column) restores the column's own type, so a bigint column comes back as a bigint instead of a number.
    • toJson(record) returns exactly the entries the record names, under the record's own keys, and now compiles to json_build_object(...) instead of reading the whole row of the first column's table. Array entries are encoded as JSON arrays, and literal entries are restored to their declared type. A record that named a column of another table used to return that table's row; it now returns the record it was given.
    await db.from(Users).select(() => ({
    card: toJson({ userId: Users.id, name: Users.username }),
    }));
    // card is inferred as { userId: bigint; name: string }

    Caveats​

    A restored document is no longer plain JSON — a bigint is not JSON-serializable — and the round trip through PostgreSQL's JSON encoding is not lossless:

    • a bigint or numeric beyond the exact range of a double is rounded by the driver's JSON parser before it is restored;
    • a timestamp comes back at millisecond precision.

    Cast to text when the exact value matters:

    await db.from(Users).select(() => ({
    card: jsonBuildObject({ id: sql<string>`${Users.id}::text` }),
    }));
    // card is inferred as { id: string }
  • 63fb292 - Thanks to @almahdi404 !

    change(cli)!: rename shell command to repl

    The interactive SQL command is now durcno repl. The old durcno shell command and its shel alias are removed, making this a breaking CLI change.

    The REPL behavior is unchanged: multi-line input, query history, formatted table output, and psql-style meta commands all work as before.

    npm exec durcno repl
  • 25fc90f - Thanks to @almahdi404 !

    change(types)!: narrow widened any slots to unknown

    Driver rows, query handlers, subqueries and rejection values are now typed instead of widened to any. Runtime behavior is unchanged; strongly typed code that relied on any may need a cast.

    A new RawRow type (Record<string, unknown>) names what every driver returns and is reused across the row pipeline:

    type RawRow = Record<string, unknown>;

    db.raw("SELECT id FROM users", [], (rows) => rows); // rows: RawRow[]

    RawRow[] now flows through $Client.getRows, $Pool.getRows, Query.rowsHandler, QueryPromise.handleRows and db.raw's handler. A handler that returns rows unchanged no longer needs an explicit generic or a cast:

    // before
    await db.raw<{ id: string; }[]>("SELECT id FROM users", [], (rows) => rows);
    // after
    await db.raw<{ id: string; }[]>("SELECT id FROM users");

    QueryPromise.catch and .then now receive unknown for the rejection reason, matching Promise.

    Subqueries reuse a single widened SelectQuery alias (WidenedSelectQuery) instead of inlining wildcard arguments at each use site. SqlFn and AggregateSqlFn default TTsType to unknown.

    Two wildcard aliases no longer collapse to any: AnyTableWithColumns and AnyCteWithColumns. As a result db.$.tables excludes relation factories instead of carrying never-typed entries.

  • e7cbc6d - Thanks to @almahdi404 !

    change(cli)!: drop deno runtime support

    durcno init no longer detects Deno, and Durcno's supported runtimes are now Node.js and Bun.

    Under Deno, the generated durcno.config.ts used to import Deno's own env loader. It now imports the standard one, like every other Node.js-compatible runtime:

    // before, under Deno
    import "@std/dotenv/load";

    // after
    import "dotenv/config";

    Bun is unaffected — it keeps its built-in loader, so no import is emitted at all.

    Why​

    On October 9, 2026 the Deno team joined Cloudflare, and the announcement set the end of the standalone runtime: one more year of monthly releases carrying bug fixes and security updates, after which development stops. Deno remains MIT-licensed and open source, so the repository lives on, but the runtime is no longer where the work goes. The team is merging celld into workerd to make the Workers programming model self-hostable, and Deno Deploy itself shuts down in six months.

    Cloudflare Workers was advertised as a supported target for the postgres connector. Durcno has never been tested against it, so the claim is removed rather than left standing as an untested promise.

    Bun stays, for reasons of its own. Its roadmap still centers on Node.js compatibility — its docs describe it as aiming to be a drop-in replacement for Node.js apps, where Node.js APIs, node_modules, and your framework work as-is — and it ships a native PostgreSQL client that Durcno targets directly through its own connector. It is also under active development rather than winding down.

    Breaking​

    • durcno init under Deno generates import "dotenv/config" instead of import "@std/dotenv/load", and installs the dotenv package alongside it. A Deno project that wants the standard library loader must import @std/dotenv/load itself.

Minor Changes​

  • cc3724e - Thanks to @almahdi404 !

    feat(cli): add exec command for non-interactive SQL

    durcno exec runs SQL against the configured database without opening a REPL. It uses the connector and credentials from durcno.config.ts, so scripts, CI jobs, and AI agents get a psql alternative that shares the project's configuration. The interactive durcno shell is unchanged.

    SQL comes from -c/--command, -f/--file, or piped stdin. Statements are split on top-level semicolons — semicolons inside strings, quoted identifiers, dollar-quoted bodies, and comments do not split — and run sequentially. The first failure is written to stderr and exits 1; success exits 0. Query data goes to stdout.

    durcno exec -c 'select * from "public"."users" limit 5'
    durcno exec -f db/seed.sql
    cat db/seed.sql | durcno exec --json

    --json prints a single valid JSON array containing the rows returned by the whole run, with 64-bit integers serialized as strings and byte arrays as hex. DDL-only input prints []. -q/--quiet suppresses timings and row counts. Data-returning meta commands are supported when they make up the entire input:

    durcno exec -c '\dt' --json

    --command and --file cannot be combined. Without either, exec reads piped stdin and never starts an interactive prompt.

Patch Changes​

  • aff0ff0 - Thanks to @almahdi404 !

    fix(indexes): allow mixed column types in index keys

    index() and uniqueIndex() used to infer a single column type from the key array, so a composite index rejected every key whose type differed from the first one. A key that mixed types — the shape the schema docs already advertised — failed to compile:

    Type 'TableColumn<..., "userId", TextColumn<...>>' is not assignable to
    type 'IndexOn<BigintColumn<...>> | StdTableColumn<BigintColumn<...>>'

    Keys are now typed as (StdTableColumn | IndexOn)[], so each key is checked as a column of its own type, and Index is no longer generic over a single column type.

    export const CartItems = table(
    "public",
    "cartItems",
    {
    id: pk(),
    userId: text({ notNull }), // text
    productId: bigint({ notNull }), // bigint
    },
    {
    indexes: (t) => [
    uniqueIndex("cart_items_user_product_idx", [t.userId, t.productId]),
    ],
    },
    );

    Operator-class keys mix the same way: index([t.id, t.email.opclass("text_pattern_ops")]).

    Generated SQL, migrations, and index naming are unchanged — the rejection was compile-time only, so existing schemas keep producing the same DDL. A composite unique index over mixed key types is now usable for ON CONFLICT targets, instead of being declared as raw SQL that generate would propose dropping.

  • 8df1254 - Thanks to @almahdi404 !

    fix(functions): cast Date results in caseWhen

    caseWhen(...) rendered a Date branch as a bare string literal when no branch referenced a column. A CASE made only of Date branches was therefore resolved by PostgreSQL as text: comparisons and inserts into timestamp columns failed, and SELECT only worked because the value was converted back to a Date after reading it.

    Date-only CASE results now render each branch as '<ISO>'::timestamptz, so the expression keeps a timestamp type. A CASE that also has a column, function, or other value operand is unchanged, since that operand already determines the type.

    const at = new Date("2025-01-01T00:00:00.000Z");
    const fallback = new Date("2020-01-01T00:00:00.000Z");

    // CASE WHEN ... THEN '...'::timestamptz ELSE '...'::timestamptz END
    await db.from(Users).select(() => ({
    at: caseWhen(eq(Users.id, id), at).else(fallback),
    }));