ball 3
ball 3
DTDrizzle Team
Created by lyron1111 on 3/26/2024 in #help
Executing raw Sql query
ok thx anyways
5 replies
DTDrizzle Team
Created by lyron1111 on 3/26/2024 in #help
Executing raw Sql query
thx, i have written this code in order to execute a sql query:
import "server-only";

import { db } from "@/db";
import { sql } from "drizzle-orm";

export async function runQuery(query: string) {
const res = await db.execute(sql.raw(query));
return res;
}
import "server-only";

import { db } from "@/db";
import { sql } from "drizzle-orm";

export async function runQuery(query: string) {
const res = await db.execute(sql.raw(query));
return res;
}
and when i call the function for this query:
const res = await runQuery(
"select * from user"
);
const res = await runQuery(
"select * from user"
);
i get [{"user":"default"}] which i also get in the drizzle studio although i do have rows in the user table:
export const users = pgTable("user", {
id: text("id")
.primaryKey()
.$defaultFn(() => uuidv4()),
name: text("name").notNull(),
password: text("password"),
email: text("email").unique().notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image")
.default("https://cdn-icons-png.flaticon.com/512/1531/1531344.png")
.notNull(),
role: userRole("role").default("USER").notNull(),
isTwoFactorEnabled: boolean("isTwoFactorEnabled").default(false).notNull(),
});
export const users = pgTable("user", {
id: text("id")
.primaryKey()
.$defaultFn(() => uuidv4()),
name: text("name").notNull(),
password: text("password"),
email: text("email").unique().notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image")
.default("https://cdn-icons-png.flaticon.com/512/1531/1531344.png")
.notNull(),
role: userRole("role").default("USER").notNull(),
isTwoFactorEnabled: boolean("isTwoFactorEnabled").default(false).notNull(),
});
is there a way to fix that (note, it does that only for the user table not any other table)
5 replies