Skip to content

Connect Node.js (Prisma, Drizzle, Knex)

All three tools take the instance’s host, port and user. Create the database first, see CLI clients. Replace the ports below with your instance’s port.

PostgreSQL:

Terminal window
DATABASE_URL="postgresql://postgres@127.0.0.1:5432/myapp"

MySQL:

Terminal window
DATABASE_URL="mysql://root@127.0.0.1:3306/myapp"

In the Prisma ORM 7 documentation the schema has only the provider, and the URL is set in prisma.config.ts.

datasource db {
provider = "postgresql" // or "mysql"
}
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
datasource: {
url: env("DATABASE_URL"),
},
});

Prisma’s docs show the URL form mysql://user:pass@host:3306/database. Leave out the password for SQLEye.

drizzle.config.ts for PostgreSQL:

import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/db/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});

For MySQL set dialect: 'mysql'. At runtime, drizzle(process.env.DATABASE_URL!) takes the same URL (the PostgreSQL guide installs pg, the MySQL guide mysql2).

Install pg for PostgreSQL or mysql2 for MySQL.

const knex = require('knex')({
client: 'pg', // 'mysql2' for MySQL
connection: {
host: '127.0.0.1',
port: 5432, // 3306 for MySQL
user: 'postgres', // 'root' for MySQL
database: 'myapp',
},
});

Sources: Prisma MySQL, Drizzle PostgreSQL, Drizzle MySQL, Knex. To see the queries these tools send, turn on capture.

SQLEye is developed and maintained by CodeROG. This page is also available as Markdown.