Skip to main content

durcno@1.0.0-alpha.20

Minor Changes​

  • 77bab8d - Thanks to @almahdi404 !

    feat(insert): add ON CONFLICT support with doNothing and doUpdateSet

    InsertQuery now supports PostgreSQL ON CONFLICT clauses 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 excluded object is a fully typed clone of the table columns, bound to PostgreSQL's EXCLUDED pseudo-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 parent InsertQuery, so .returning() can be chained afterward.
  • bb4196e - Thanks to @almahdi404 !

    feat(query-builder): support left joins

    leftJoin is now fully supported in the query builder! Columns and SQL functions originating from a leftJoin are 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 column
    lowerPostTitle: 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 use info().

  • 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.