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

Supabase · Database · all subjects

connecting/drizzle

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 ORM overview and setup

Drizzle ORM is a TypeScript ORM for SQL databases designed with maximum type safety. You can use Drizzle to connect to Supabase databases. When using Drizzle, you can turn off the Supabase Data API (PostgREST) in the API Settings if you plan to use only Drizzle.

Drizzle installation command

Install Drizzle ORM and its dependencies with: npm i drizzle-orm postgres. Then install the development dependency with: npm i -D drizzle-kit.

Drizzle schema definition example for PostgreSQL

To define models in Drizzle, create a schema.ts file using drizzle-orm/pg-core. Example: import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core"; export const users = pgTable('users', { id: serial('id').primaryKey(), fullName: text('full_name'), phone: varchar('phone', { length: 256 }), });

Drizzle connection setup with postgres-js

Connect to Supabase using the Connection Pooler. Copy the URI from the Shared Pooler option in the Connect panel and save it as the DATABASE_URL environment variable. When using Drizzle with postgres-js, create a client with: import { drizzle } from 'drizzle-orm/postgres-js'; import postgres from 'postgres'; const client = postgres(connectionString, { prepare: false }); export const db = drizzle(client); The prepare: false option is required because prefetch is not supported for Transaction pool mode.

Drizzle local development connection string adaptation

When using Supabase locally with Docker, the SUPABASE_DB_URL connection string needs to be adapted to work with the Docker resolver. If the connection string includes 'postgres:postgres@supabase_db_', extract the resolver hostname from the underscore-separated portion.

Connection Pooler required for Drizzle

When connecting Drizzle to Supabase, use the Connection Pooler option (Shared Pooler) from the Connect panel, not the direct connection. Save the URI as the DATABASE_URL environment variable and replace the password placeholder with your actual database password.

Give your agent this brain