Acro
Acro
Explore posts from servers
DTDrizzle Team
Created by Acro on 3/21/2024 in #help
Examples for Error Handling?
I am looking through docs on how to handle DB errors, but not finding a list of error codes. For example, UNIQUE or NOT NULL constraints to check for. Or is this something I need to look at Postgres.js docs for? Pseudocode below using Sqlite, but want to know for Postgres.js
try {
...
} catch (e) {
if (e instanceof SqliteError && e.code === "SQLITE_CONSTRAINT_UNIQUE") {
return setError(form, 'email', "E-mail already used")
}
}
try {
...
} catch (e) {
if (e instanceof SqliteError && e.code === "SQLITE_CONSTRAINT_UNIQUE") {
return setError(form, 'email', "E-mail already used")
}
}
2 replies
DTDrizzle Team
Created by Acro on 3/21/2024 in #help
When to use what? drizzle-kit push:* Vs. having a file with drizzle migrate client?
Option 1: package.json script drizzle-kit push:pg Option 2: migrate.ts script
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

const migrationClient = postgres("postgres://postgres:[email protected]:5432/db", { max: 1 });
migrate(drizzle(migrationClient), ...)
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

const migrationClient = postgres("postgres://postgres:[email protected]:5432/db", { max: 1 });
migrate(drizzle(migrationClient), ...)
6 replies