Drizzle error with React Query

Hello, I'm trying to get real time updates for my event log that im keeping in supabase. I had no issues accessing data trough Drizzle till i tried to make React query . I'm adding a code where i have simple supabase data fetch and drizzle (commented). when trying wtih drizzle one im getting the error with postgres picture bellow.
import { eventsBLC } from "~/schema/eventsBLC";
import { db } from "./drizzleClient";
import { users } from "~/schema/users";
import { desc, eq } from "drizzle-orm";
import { useQuery } from "@tanstack/react-query";
import { supabase } from "~/lib/supabaseClient";

// export const getBLCLogs = async () => {
// const data = await db
// .select()
// .from(eventsBLC)
// .limit(4)
// .orderBy(desc(eventsBLC.created_at))
// .leftJoin(users, eq(eventsBLC.userId, users.id));
// return data;
// };
export const supabaseBLC = async () => {
const { data: eventsBLC, error } = await supabase
.from("eventsBLC")
.select("*")
.limit(4)
.order("id", { ascending: false });
return eventsBLC;
};

export function useGetBLCPosts() {
return useQuery({
queryFn: async () => supabaseBLC(),
queryKey: ["logs"],
});
}
import { eventsBLC } from "~/schema/eventsBLC";
import { db } from "./drizzleClient";
import { users } from "~/schema/users";
import { desc, eq } from "drizzle-orm";
import { useQuery } from "@tanstack/react-query";
import { supabase } from "~/lib/supabaseClient";

// export const getBLCLogs = async () => {
// const data = await db
// .select()
// .from(eventsBLC)
// .limit(4)
// .orderBy(desc(eventsBLC.created_at))
// .leftJoin(users, eq(eventsBLC.userId, users.id));
// return data;
// };
export const supabaseBLC = async () => {
const { data: eventsBLC, error } = await supabase
.from("eventsBLC")
.select("*")
.limit(4)
.order("id", { ascending: false });
return eventsBLC;
};

export function useGetBLCPosts() {
return useQuery({
queryFn: async () => supabaseBLC(),
queryKey: ["logs"],
});
}
No description
10 Replies
Angelelz
Angelelz5mo ago
I don't think this has anything to do with react query. Are you using bun, or in a different environment than node? Do you have Middleware running Postgres call?
Erla
Erla5mo ago
No to all of them. Im only using Postress to initiate drizzle client (as per tutorials)
Angelelz
Angelelz5mo ago
Are you trying to run that code in the browser?
nk
nk5mo ago
@Erla You're trying to put backend code on the frontend.
Erla
Erla5mo ago
Yes ,apparently postgres package does not support being imported to the client side. That's why there is no issue with default supabase client to use in react query( client side for real time data) . So there are 2 ways for me. Either use 2 connections to db(drizzle and supabase for client side real time data) , or refactor the code to API route. Since I'm new to databases in general ,would appreciate comments if there is anyway to get real time data, solely with drizzle . Thank you.
Angelelz
Angelelz5mo ago
Not familiar enough be give a sensible opionion
rphlmr ⚡
rphlmr ⚡5mo ago
nk is right, React query runs in the browser, so you can't (and would not) make DB calls here. Supabase SDK is working because it is its main purpose: to give a way to query a DB without a server. Behind the scenes, Supabase is wrapping your query in an HTTP request sent to PostgREST (a third service offered by Supabase). + you probably have added RLS policies to prevent open access to you DB.
rphlmr ⚡
rphlmr ⚡5mo ago
You could safely use Supabase Realtime here (https://supabase.com/docs/guides/realtime) and Drizzle in API routes. Or, only use the Supabase SDK (without Drizzle) if you are more comfortable with it.
Realtime | Supabase Docs
Send and receive messages to connected clients.
rphlmr ⚡
rphlmr ⚡5mo ago
Since you use NextJS, you can use Drizzle in a Server Component (without React Query), but this is relatively new and it will depend on how you feel comfortable with this mental model 😄
Erla
Erla5mo ago
Thanks for advice , will definetely look into all of the options.
Want results from more Discord servers?
Add your server
More Posts
Alter type enum column ending in replace rather than alterIs there a fix for it? It should alter the column rather than deleting and creating it.`no such table: user` in production with drizzle + sqlite + next.js?i have 2 sqlite databases: 1. `example.dev.sqlite` - for development 2. `example.prod.sqlite` - forIf I pass an object with a property that has 'undefined' as the value, will it be ignored?If I am updating or inserting data and passing an object, for instance: ```ts const dbData = { idAre there any examples with Drizzle + SvelteKit + `better-sqlite3`?Hi, I can't get drizzle working, error after error (lol). I'm looking for something bare minimum thaIs it possible to "select distinct" while using a "with clause"?Hi all, TLDR: It seems that the `selectDistinct` function does not exist on the object I get afteCan't figure out how to filter by JSON column with array dataI have a query with some joins that I have built up so far: ```ts // not the full query const distiInterface for both db and txI am trying to create some utility functions that would accept both DB and transaction. I tried theDrizzle Studio black screenHi, I'm trying to use Drizzle Studio for the first time. We use Postgres. Migrations and the clientCan't edit datetime column in drizzle studio "Error: value.toISOString is not a function"So I'm seeing my database with some data, and for the two `datetime` fields I've had a strange issueHelp with a requestHey, guys, I'm new here. Here's my schema. export const Anime = pgTable('Anime', { id: serial('id