durcno@1.0.0-alpha.20
Minor Changes
-
77bab8d - Thanks to @almahdi404 !
feat(insert): add ON CONFLICT support with doNothing and doUpdateSet
InsertQuerynow supports PostgreSQLON CONFLICTclauses through a fluent, type-safe API.Chain
.onConflict(...columns)after.values()to define the conflict target, then choose an action:.doNothing()— skip the insert when a conflict occurs.doUpdateSet(set, where?)— upsert rows by returning a column assignment map from a callback
await db.insert(Users).values({ username: "alice", email: "new@example.com", type: "user" }).onConflict(Users.username).doUpdateSet(({ excluded }) => ({email: excluded.email,type: Users.type,}));await db.insert(Users).values({ username: "alice", type: "user" }).onConflict().doNothing();The
excludedobject is a fully typed clone of the table columns, bound to PostgreSQL'sEXCLUDEDpseudo-table.- Generated SQL uses
EXCLUDED."column"when appropriate. doUpdateSet()is only available after providing at least one conflict target column.- Both
.doNothing()and.doUpdateSet()return the parentInsertQuery, so.returning()can be chained afterward.
-
bb4196e - Thanks to @almahdi404 !
feat(query-builder): support left joins
leftJoinis now fully supported in the query builder! Columns and SQL functions originating from aleftJoinare now correctly inferred as nullable (T | null) in TypeScript, matching runtime SQL behavior when a joined record doesn't exist.const query = db.from(Users).leftJoin(Posts, eq(Users.id, Posts.userId)).select({username: Users.username,postTitle: Posts.title, // Left joined columnlowerPostTitle: lower(Posts.title), // Left joined SQL function});type ReturnType = Awaited<typeof query>;// Inferenced as:// {// username: string;// postTitle: string | null;// lowerPostTitle: string | null;// }[] -
cb75a11 - Thanks to @almahdi404 !
feat(logger): add error logging for failed queries
Query execution logging now reports both successful and failed queries. When a query throws, the logger receives an
error()call with the SQL text, bound arguments, and elapsed time, while successful executions continue to useinfo(). -
6ca9338 - Thanks to @almahdi404 !
impr(prequery): improve prepared query support
Prepared query support now works more consistently for .insert() and .query() flows. The implementation now preserves the prepared statement's return type and correctly handles argument binding for values and filters, which makes prequery-based workflows more reliable.
This change also adds dedicated integration coverage for prepared select, insert, and query flows, helping ensure these paths remain stable as the query builder evolves.