DT
Drizzle Team•10mo ago
ethan

having issues with querying db

hi, ive recently migrated from prisma to drizzle but i havne't had any luck with querying the data. ive attached pictures of my drizzle config and where i instantiate and export the db. ive also included a pic of a function where i try to query a user by their username. after line 67, no lines of code are run and nothing is ever returned from the query. please let me know if im doing something wrong, thanks in advance!
No description
No description
No description
7 Replies
HotBBQSauce
HotBBQSauce•10mo ago
Remove resolve dirname or is that updated in the docs? Im not sure i cant spot where it could error have you made sure the database url is correct? You havent shared the queries it might probaly be just an error in how its queried Wait why are you using drizzle with pg and querying data using redis? This has nothing to do with drizzle your error i supose? If only the drizzle query is not working i suppose it does work but you are using ilike incorrectly
ethan
ethanOP•10mo ago
im just copying code from the docs here: https://orm.drizzle.team/learn/migrate/migrate-from-prisma#overview-of-the-migration-process i tried it without dirname and same issue
Drizzle ORM - Learn
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
ethan
ethanOP•10mo ago
yeah its the same database url that i was connecting to prisma with oh no i just have redis in the function to check if theres any cached data to pull. if no redis data is found itll query the db which is where the function is halting none of my other queries work either like getting a user by id so i figured it would be a bigger overarching issue with the config, schema, or the way im instantiating db or something like that
Mykhailo
Mykhailo•10mo ago
Hello, @ethan! Could you please console.log() your database url?I think the problem is related to env, the url might be undefined or try to add
import 'dotenv/config';
import 'dotenv/config';
to your config and db files
ethan
ethanOP•10mo ago
oh hey i think i solved the issue... im using supabase and have connection pooling enabled. if you have connection pooling enabled on supabase you have to turn prepare off so something like this will work:
import { drizzle } from "drizzle-orm/postgres-js";
import * as schema from "./schema";
import postgres from "postgres";

const client = postgres(process.env.DATABASE_URL!, { prepare: false });

export const db = drizzle(client, { schema });
import { drizzle } from "drizzle-orm/postgres-js";
import * as schema from "./schema";
import postgres from "postgres";

const client = postgres(process.env.DATABASE_URL!, { prepare: false });

export const db = drizzle(client, { schema });
figured id put the solution here in case anyone else was facing this issue 🙂 thanks for the help
Mykhailo
Mykhailo•10mo ago
Btw, in your first example you was using node-postgres and problem could be that you forgot to add this line
No description
ethan
ethanOP•10mo ago
ohh gotcha my mistake. thanks for catching that
Want results from more Discord servers?
Add your server