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

mssql/connections

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

MSSQL drivers and providers supported by Drizzle ORM

Drizzle ORM supports multiple MSSQL drivers and providers for database connections. Documentation for MSSQL connection setup is available in the MSSQL get-started guide.

Basic withReplicas() usage with MSSQL

Example showing how to set up withReplicas() with MSSQL: Create separate drizzle instances for the primary database and read replicas using separate ConnectionPool connections, then pass the primary db and replica array to withReplicas(). SELECT queries will automatically use replicas while INSERT, UPDATE, and DELETE operations use the primary database.

$primary key to force primary database reads

When using withReplicas(), you can use the $primary key on the db instance to force read operations to use the primary database instead of replicas. Usage: db.$primary.select().from(table).

Custom replica selection logic with withReplicas()

withReplicas() accepts an optional third parameter: a custom selection function that receives the array of replicas and returns the selected replica. This allows implementation of custom load balancing logic such as weighted probability, round-robin, or any other selection strategy. The function signature is (replicas: ReplicaClient[]) => ReplicaClient.

Weighted replica selection example

Example of custom replica selection using weighted probability: The function calculates a random number and iterates through replicas with cumulative probability weights to determine which replica to use. In this example, the first replica has 70% chance of selection and the second has 30% chance. The implementation shows how to set up: const db = withReplicas(primaryDb, [read1, read2], (replicas) => { const weight = [0.7, 0.3]; let cumulativeProbability = 0; const rand = Math.random(); for (const [i, replica] of replicas.entries()) { cumulativeProbability += weight[i]!; if (rand < cumulativeProbability) return replica; } return replicas[0]! });

Give your agent this brain