Self hosted Postgres on Create t3 Turbo

I am low key struggling to convert create-t3-turbo db package from using Vercel Postgres to Railway postgres connection. This is what I have now in my client.ts
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";

import * as schema from "./schema";

const pool = new Pool({
connectionString: process.env.POSTGRES_URL,
});

export const db = drizzle({ client: pool, schema });
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";

import * as schema from "./schema";

const pool = new Pool({
connectionString: process.env.POSTGRES_URL,
});

export const db = drizzle({ client: pool, schema });
I can run pnpm db:push and it works but all the types in tRPC are breaking when passing db for zod infrence. Would love help don't see the schma types coming through on DB being passed into the API package. This has to be an issue someone else has solved. Not seeing schmea notes in Drizzel postgres-node docs. These are the only types coming back on the db var
{
$client: Pool;
}
{
$client: Pool;
}
5 Replies
LinnJS
LinnJSOP2mo ago
I think I figured out after walking away and sleeping on it . The issue was not having pg and @types/pg in the api when I had then in the db package. With this client and adding those packages to db and api ts errors went away. Here is my client
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as schema from "./schema";

const pool = new Pool({
connectionString: process.env.POSTGRES_URL,
});

export const db = drizzle({ client: pool, schema });
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as schema from "./schema";

const pool = new Pool({
connectionString: process.env.POSTGRES_URL,
});

export const db = drizzle({ client: pool, schema });
Stuck at this point now with errors coming from auth looks like backend stuff is getting bundled on the client
LinnJS
LinnJSOP2mo ago
LinnJS
LinnJSOP2mo ago
I tried using the webpack in next config workaround but does not seem to be working.
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback = {
fs: false,
path: false,
stream: false,
};
}
return config;
},
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback = {
fs: false,
path: false,
stream: false,
};
}
return config;
},
I got TypeScript happy with the new driver but now when I start up the nextjs app and load the page I get the following error.
LinnJS
LinnJSOP2mo ago
LinnJS
LinnJSOP2mo ago
I opened a Github issue on create-t3-turbo for this issue.

Did you find this page helpful?