Skip to main content

durcno@1.0.0-alpha.38

Major Changes​

  • 8404050 - Thanks to @almahdi404 !

    change(filters)!: render null predicates as SQL NULL

    JavaScript null is accepted anywhere a predicate is expected and renders as PostgreSQL NULL. Column comparisons also accept null and keep native SQL semantics, so eq(column, null) produces column = NULL; use isNull(column) to match null values.

    undefined is no longer accepted as a condition, and and() / or() require at least one argument. Use true as the neutral condition for and() and false as the neutral condition for or().

    await db
    .from(Users)
    .select("*")
    .where(() =>
    and(
    eq(Users.type, "admin"),
    status ? eq(Users.status, "active") : true,
    )
    );

Minor Changes​

  • db685ff - Thanks to @almahdi404 !

    feat(qb): add cross join support

    SelectBuilder now supports .crossJoin(table) for Cartesian products without an ON callback. It accepts tables and CTEs, keeps joined columns non-nullable, and composes with inner and left joins and the existing SELECT clauses.

    const rows = await db
    .from(Users)
    .crossJoin(Posts)
    .select(() => ({ username: Users.username, title: Posts.title }));
  • d95ee91 - Thanks to @almahdi404 !

    feat: add pg_trgm similarity and predicate helpers

    Durcno can now call the pg_trgm functions and operators that its existing gin_trgm_ops indexes support. The scalar builders similarity(), wordSimilarity(), strictWordSimilarity(), and showTrgm() are first-class SqlFn expressions: results infer as number (or number | null for nullable operands), Arg placeholders carry through as prepared parameters, and scores compose with greatest(), asc(), and desc(). showTrgm() returns string[].

    Three filters cover the similarity operators: similar() renders %, wordSimilar() renders <%, and strictWordSimilar() renders <<%. The word operators keep PostgreSQL's argument order, with the search term first and the text second.

    const results = await db
    .from(Articles)
    .select(() => ({
    score: greatest(
    tsRankCd(Articles.search, websearchToTsquery(term)),
    similarity(Articles.body, term),
    ),
    }))
    .where(() => wordSimilar(term, Articles.title))
    .orderBy(() => desc(similarity(Articles.body, term)));

    As with other extensions, enable pg_trgm in the database before using these helpers.

  • 321870c - Thanks to @almahdi404 !

    feat(filters): add LIKE/ILIKE ESCAPE modifier

    like() and ilike() now support a chainable .escape() modifier for PostgreSQL's ESCAPE clause. It accepts a string literal or an Arg<string>, so a custom escape character also works in prepared queries.

    await db
    .from(Interests)
    .select("*")
    .where(() => ilike(Interests.content, containsPattern(token)).escape("!"));

    escape() returns a new condition, leaving the original predicate unchanged. Existing predicates keep PostgreSQL's default backslash escape.

Patch Changes​

  • ba7d643 - Thanks to @almahdi404 !

    fix(columns/pgvector): validate bit and vector values

    pgvector.bit now rejects values that are not strings of 0 and 1 before building SQL. This closes a path where a quote in the value could escape the B'…' literal.

    pgvector.vector and pgvector.halfvec now require an array whose elements are all finite numbers. Both checks run on the SQL-literal path and the driver path, so inserts, updates, comparisons, and prepared statements fail early instead of sending unsafe or invalid SQL.

    await db.insertInto(Embeddings).values({
    bits: "1' || pg_sleep(5) || '", // throws: Invalid bit string value
    embedding: [1, Number.NaN, 3], // throws: Invalid vector element
    });
  • fa243d5 - Thanks to @almahdi404 !

    fix(qb): omit shared column names from select-all with joins

    select("*") no longer returns field names declared by two or more tables in the join. Ambiguous names are removed from both the inferred result type and the converted rows. An explicit .select(() => ({ ... })) projection still reads any of those columns.

    const rows = await db
    .from(Users)
    .innerJoin(Posts)
    .on(() => eq(Users.id, Posts.userId))
    .select("*");
    // `id` and `createdAt` are absent when both tables declare them