Drizzle cannot run directly in loader/action

So I have been in the process of switching over from prisma to drizzle and I have hit a huge roadblock. Right now the only way that I can run queries is in server files. Every-time I try to run drizzle queries directly in loaders or actions it prevents the page from loading. The only way I can get it to work is to move the queries into server files and then import it into the route that I am using it in. Following the chain of issues down the call stack I end up in an aws-sdk file with the error code "No Providers in Chain"
1 Reply
iLikeBikes
iLikeBikesOP15mo ago
A little bit more context is that I am using drizzle and remix in a turbo repo. I have attempted to load drizzle in a server file by doing the following
// database package
import { drizzle as _drizzle } from "drizzle-orm/node-postgres";
import * as _drizzleValues from "../drizzle/schema";
import type * as _drizzleTypes from "../drizzle/schema";
import { Pool } from "pg";

if (!process.env.DATABASE_URL) throw Error("No database url found");
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
export const drizzle = _drizzle(pool);

globalForPrisma.prisma = prisma;

const { tables, ...drizzleValues } = _drizzleValues;
export { _drizzleTypes as drizzleTypes };
export { tables, drizzleValues };
// database package
import { drizzle as _drizzle } from "drizzle-orm/node-postgres";
import * as _drizzleValues from "../drizzle/schema";
import type * as _drizzleTypes from "../drizzle/schema";
import { Pool } from "pg";

if (!process.env.DATABASE_URL) throw Error("No database url found");
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
export const drizzle = _drizzle(pool);

globalForPrisma.prisma = prisma;

const { tables, ...drizzleValues } = _drizzleValues;
export { _drizzleTypes as drizzleTypes };
export { tables, drizzleValues };
// db.server.ts
import {drizzle} from 'database/index';
export const db = drizzle;
// db.server.ts
import {drizzle} from 'database/index';
export const db = drizzle;
I figured out that tables cannot be used directly. I had to pull in the database module from another turborepo package. And I needed to pull the table definitions through a ‘.server.ts’ file before using in a routes loader
Want results from more Discord servers?
Add your server