durcno@1.0.0-alpha.38
Major Changes
-
8404050 - Thanks to @almahdi404 !
change(filters)!: render null predicates as SQL NULL
JavaScript
nullis accepted anywhere a predicate is expected and renders as PostgreSQLNULL. Column comparisons also acceptnulland keep native SQL semantics, soeq(column, null)producescolumn = NULL; useisNull(column)to match null values.undefinedis no longer accepted as a condition, andand()/or()require at least one argument. Usetrueas the neutral condition forand()andfalseas the neutral condition foror().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
SelectBuildernow supports.crossJoin(table)for Cartesian products without anONcallback. It accepts tables and CTEs, keeps joined columns non-nullable, and composes with inner and left joins and the existingSELECTclauses.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_trgmfunctions and operators that its existinggin_trgm_opsindexes support. The scalar builderssimilarity(),wordSimilarity(),strictWordSimilarity(), andshowTrgm()are first-classSqlFnexpressions: results infer asnumber(ornumber | nullfor nullable operands),Argplaceholders carry through as prepared parameters, and scores compose withgreatest(),asc(), anddesc().showTrgm()returnsstring[].Three filters cover the similarity operators:
similar()renders%,wordSimilar()renders<%, andstrictWordSimilar()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_trgmin the database before using these helpers. -
321870c - Thanks to @almahdi404 !
feat(filters): add LIKE/ILIKE ESCAPE modifier
like()andilike()now support a chainable.escape()modifier for PostgreSQL'sESCAPEclause. It accepts a string literal or anArg<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.bitnow rejects values that are not strings of0and1before building SQL. This closes a path where a quote in the value could escape theB'…'literal.pgvector.vectorandpgvector.halfvecnow 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 valueembedding: [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