new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle ORM · all subjects

query builder & operators

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Drizzle query syntax types: SQL-like vs Relational

Drizzle offers two ways to query the database: SQL-like syntax and Relational syntax. SQL-like syntax replicates SQL directly and allows you to know exactly what query will be generated. Relational syntax is used for fetching relational, nested data more conveniently and performantly without worrying about joins or data mapping.

SQL-like query example with select, join, and where

Example of SQL-like syntax: `await db.select().from(posts).leftJoin(comments, eq(posts.id, comments.post_id)).where(eq(posts.id, 10))` generates the SQL query `SELECT * FROM posts LEFT JOIN comments ON posts.id = comments.post_id WHERE posts.id = 10`.

SQL-like queries cover operations

SQL-like queries support select, insert, update, delete, as well as aliases, WITH clauses, subqueries, prepared statements, and more.

Compose WHERE filters independently and reuse

Filters can be composed independently using an array of SQL conditions, then passed to the where clause using the `and()` function. Example: `const filters: SQL[] = []; if (name) filters.push(like(products.name, name)); ... db.select().from(products).where(and(...filters));`

Compose subqueries into separate variables

Subqueries can be defined in separate variables and aliased using `.as()`, then used in a main query. Example: `const subquery = db.select().from(internalStaff).leftJoin(customUser, eq(internalStaff.userId, customUser.id)).as('internal_staff'); const mainQuery = await db.select().from(ticket).leftJoin(subquery, eq(subquery.internal_staff.userId, ticket.staffId));`

Drizzle SQL philosophy

Drizzle is designed to be SQL-like at its core, embracing SQL rather than abstracting it away. This means if you know SQL, you know Drizzle, with little to no learning curve and full access to the power of SQL.

Give your agent this brain