durcno@1.0.0-alpha.34
Major Changes
-
e955365 - Thanks to @almahdi404 !
change(query)!: split the join clause into an .on() method
innerJoinandleftJoineach took the joined table and theONcondition in one call. The condition is now supplied to a separate.on()on the join builder those two methods return.// beforedb.from(Users).innerJoin(Posts, () => eq(Users.id, Posts.userId));// afterdb.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 anON, 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
SELECTwhose projection contains a nested aggregate — an aggregate wrapped in another function, such asround(avg(rating), 1)— used to treat it as a scalar and put it inGROUP BY, producingaggregate functions are not allowed in GROUP BY. When every projection item is an aggregate, the query now emits noGROUP BYand returns one aggregate row.// aggregates only: no GROUP BY, one rowawait db.from(Reviews).select(() => ({totalCount: count("*"),averageRating: round(avg(Reviews.rating), 1),}));// a wrapped aggregate beside a plain column: group by the column aloneawait 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/SETvalues andFILTER (WHERE ...)refuse an aggregate at any nesting depth, at compile time.WHEREnow also rejects a barecount("*").HAVING,ORDER BYand groupedCASE WHENconditions accept one, wrapped or not.ORDER BYonly applies when the query aggregates; otherwise PostgreSQL rejects the query itself.- An aggregate in a
CASE WHENcondition is part of the CASE, not a grouping key; columns read by a plain condition join the autoGROUP BY.
Also fixed
caseWhen(...)is accepted in.set(); thecoalesce(...)workaround is unnecessary.avg(round(sum(x), 2))is invalid SQL and is now a compile error.having(() => gt(round(avg(x), 1), 2))andorderBy(() => 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.tsmeasures it.API
SqlFn.isAggregateis nowSqlFn.hasAggregate, andSqlFn.sqlFnTypeexposes 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
int8becomes a number, atimestamptza 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 -> bigintcreatedAt: Users.createdAt, // timestamptz column -> Date}),}));// card is inferred as { id: bigint; createdAt: Date }The restore covers
jsonBuildObject,jsonbBuildObject,jsonAgg,jsonbAgg,jsonBuildArray,jsonbBuildArray,toJson,toJsonb,jsonStripNullsandjsonbStripNulls. A literal operand is restored as well — aDatecomes back as aDateand abigintas abigint.An array literal is encoded as a JSON array in every JSON expression — empty, mixed,
bigint, andDatearrays included — and its elements are restored to their declared types.toJson/toJsonbalso accept scalarstring,null, and array targets.Breaking
toJson(table)returns the JavaScript column names, the ones its type always promised —createdAt, notcreated_at.toJson(column)restores the column's own type, so abigintcolumn comes back as abigintinstead of a number.toJson(record)returns exactly the entries the record names, under the record's own keys, and now compiles tojson_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
bigintis not JSON-serializable — and the round trip through PostgreSQL's JSON encoding is not lossless:- a
bigintornumericbeyond 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 olddurcno shellcommand and itsshelalias 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 onanymay need a cast.A new
RawRowtype (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.handleRowsanddb.raw's handler. A handler that returns rows unchanged no longer needs an explicit generic or a cast:// beforeawait db.raw<{ id: string; }[]>("SELECT id FROM users", [], (rows) => rows);// afterawait db.raw<{ id: string; }[]>("SELECT id FROM users");QueryPromise.catchand.thennow receiveunknownfor the rejection reason, matchingPromise.Subqueries reuse a single widened
SelectQueryalias (WidenedSelectQuery) instead of inlining wildcard arguments at each use site.SqlFnandAggregateSqlFndefaultTTsTypetounknown.Two wildcard aliases no longer collapse to
any:AnyTableWithColumnsandAnyCteWithColumns. As a resultdb.$.tablesexcludes relation factories instead of carryingnever-typed entries. -
e7cbc6d - Thanks to @almahdi404 !
change(cli)!: drop deno runtime support
durcno initno longer detects Deno, and Durcno's supported runtimes are now Node.js and Bun.Under Deno, the generated
durcno.config.tsused to import Deno's own env loader. It now imports the standard one, like every other Node.js-compatible runtime:// before, under Denoimport "@std/dotenv/load";// afterimport "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
celldintoworkerdto 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
postgresconnector. 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 initunder Deno generatesimport "dotenv/config"instead ofimport "@std/dotenv/load", and installs thedotenvpackage alongside it. A Deno project that wants the standard library loader must import@std/dotenv/loaditself.
Minor Changes
-
cc3724e - Thanks to @almahdi404 !
feat(cli): add exec command for non-interactive SQL
durcno execruns SQL against the configured database without opening a REPL. It uses the connector and credentials fromdurcno.config.ts, so scripts, CI jobs, and AI agents get apsqlalternative that shares the project's configuration. The interactivedurcno shellis 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 exits1; success exits0. Query data goes to stdout.durcno exec -c 'select * from "public"."users" limit 5'durcno exec -f db/seed.sqlcat db/seed.sql | durcno exec --json--jsonprints 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/--quietsuppresses timings and row counts. Data-returning meta commands are supported when they make up the entire input:durcno exec -c '\dt' --json--commandand--filecannot be combined. Without either,execreads piped stdin and never starts an interactive prompt.
Patch Changes
-
aff0ff0 - Thanks to @almahdi404 !
fix(indexes): allow mixed column types in index keys
index()anduniqueIndex()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 totype 'IndexOn<BigintColumn<...>> | StdTableColumn<BigintColumn<...>>'Keys are now typed as
(StdTableColumn | IndexOn)[], so each key is checked as a column of its own type, andIndexis no longer generic over a single column type.export const CartItems = table("public","cartItems",{id: pk(),userId: text({ notNull }), // textproductId: 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 CONFLICTtargets, instead of being declared as raw SQL thatgeneratewould propose dropping. -
8df1254 - Thanks to @almahdi404 !
fix(functions): cast Date results in caseWhen
caseWhen(...)rendered aDatebranch as a bare string literal when no branch referenced a column. A CASE made only of Date branches was therefore resolved by PostgreSQL astext: comparisons and inserts into timestamp columns failed, andSELECTonly worked because the value was converted back to aDateafter 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 ENDawait db.from(Users).select(() => ({at: caseWhen(eq(Users.id, id), at).else(fallback),}));