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 · PostgreSQL · all subjects

pg-proxy

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 HTTP proxy driver callback signature

The Drizzle proxy driver accepts an async callback function with three parameters: sql (query string with placeholders), params (array of parameters), and method (string: 'all' or 'execute' depending on the SQL statement). The callback must return an object with a rows property containing either string[][] for 'all' methods or string[] for 'execute' methods.

Drizzle proxy driver use cases

Drizzle Proxy is used when implementing custom driver communication with the database. Common use cases include adding custom logic at the query stage with existing drivers and implementing an HTTP driver that sends queries to a server, executes them on the database, and returns raw data for Drizzle ORM to map to results.

HTTP proxy method field values

The method field in the HTTP proxy callback is set to one of two values depending on the SQL statement: 'all' for queries that return multiple rows, and 'execute' for statements that execute but do not return multiple rows.

Drizzle proxy return value format

When method is 'execute', return {rows: string[]}. For all other cases, return {rows: string[][]}. Drizzle always waits for one of these two return formats.

HTTP proxy client implementation example

Import drizzle from 'drizzle-orm/pg-proxy' and pass an async callback function that makes HTTP POST requests to a backend server with sql, params, and method in the request body. The server should execute the query and return raw rows data, which the callback wraps in {rows: rows.data}.

HTTP proxy server implementation with node-postgres

The server receives POST requests containing sql, params, and method. It should use a node-postgres Client to execute the query by calling client.query({text: sqlBody, values: params, rowMode: method === 'all' ? 'array': undefined}). The rowMode: 'array' option converts rows to arrays when method is 'all', otherwise undefined returns rows as objects. Multiple queries must be prevented by removing semicolons from sql.

Give your agent this brain