Unable to use db.query but able to use reqular db.select

I had the problem with using Drizzle Queries, it isn't working but works with regular select my schema :
export const menuTable = pgTable('menu', {
id: varchar('id', { length: 255 }).primaryKey(),
name: varchar('name', { length: 100 }),
urlRestrict: varchar('url_restrict', { length: 100 }),
svg: varchar('svg', { length: 512 })
});

export const menuTableRelations = relations(menuTable, ({ many }) => ({
menuRole: many(roleToMenuTable),
SubMenu: many(subMenuTable)
}));

export const subMenuTable = pgTable('sub_menu', {
id: varchar('id', { length: 255 }).primaryKey(),
name: varchar('name', { length: 100 }),
urlRestrict: varchar('url_restrict', { length: 100 }),
menuId: varchar('menu_id')
.notNull()
.references(() => menuTable.id, { onDelete: 'cascade' })
.notNull()
});
export const menuTable = pgTable('menu', {
id: varchar('id', { length: 255 }).primaryKey(),
name: varchar('name', { length: 100 }),
urlRestrict: varchar('url_restrict', { length: 100 }),
svg: varchar('svg', { length: 512 })
});

export const menuTableRelations = relations(menuTable, ({ many }) => ({
menuRole: many(roleToMenuTable),
SubMenu: many(subMenuTable)
}));

export const subMenuTable = pgTable('sub_menu', {
id: varchar('id', { length: 255 }).primaryKey(),
name: varchar('name', { length: 100 }),
urlRestrict: varchar('url_restrict', { length: 100 }),
menuId: varchar('menu_id')
.notNull()
.references(() => menuTable.id, { onDelete: 'cascade' })
.notNull()
});
my drizzle config:
import { drizzle } from 'drizzle-orm/node-postgres';
import { Client } from 'pg';
import * as dotenv from 'dotenv';
dotenv.config();

const client = new Client({
connectionString: process.env.DATABASE_URL
});

await client.connect();
const db = drizzle(client);

export async function GET() {
const result = await db.query.
}
import { drizzle } from 'drizzle-orm/node-postgres';
import { Client } from 'pg';
import * as dotenv from 'dotenv';
dotenv.config();

const client = new Client({
connectionString: process.env.DATABASE_URL
});

await client.connect();
const db = drizzle(client);

export async function GET() {
const result = await db.query.
}
and i can't import with @/db/schema
2 Replies
Luxaritas
Luxaritas8mo ago
You need to import your schema and pass it to the drizzle initializer function - if you're having difficulties with importing the schema, that probably has something to do with your typescript and/or build config (if you're running into specific errors, I may be able to help with more details').
cumironin
cumironin8mo ago
thanks for this