© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
3 replies
zach

How can I read the table name and schema name of a created drizzle table instance?

Given a schema defined like this.

import { pgSchema, serial, text, varchar } from "drizzle-orm/pg-core";

export const core = pgSchema(“core”);

export const users = core.table("users", {
  id: serial("id").primaryKey(),
  fullName: text("full_name"),
  phone: varchar("phone", { length: 256 }),
});

export type User = typeof users.$inferSelect;
import { pgSchema, serial, text, varchar } from "drizzle-orm/pg-core";

export const core = pgSchema(“core”);

export const users = core.table("users", {
  id: serial("id").primaryKey(),
  fullName: text("full_name"),
  phone: varchar("phone", { length: 256 }),
});

export type User = typeof users.$inferSelect;


I have this file, where I'm importing the users table schema above. How can I access the string value of the table name and schema name that this users table refers to?
import { users } from "./schema";

// Expected output: “core.users”
function myTableName() {
  const tableName = users._.name;
  const tableSchema = users._.schema;

  const fullName = `${tableSchema}.${tableName}`;

  console.log(`My table name: ${fullName}`);

  return fullName;
}
import { users } from "./schema";

// Expected output: “core.users”
function myTableName() {
  const tableName = users._.name;
  const tableSchema = users._.schema;

  const fullName = `${tableSchema}.${tableName}`;

  console.log(`My table name: ${fullName}`);

  return fullName;
}


I would expect the above function to work, since typescript autocompletes the
._.name
._.name
and
._.schema
._.schema
values in my editor, but when the code runs, the underscore property is undefined. Is there something excluding this property from the final build? Please let me know if there is a way to accomplish this or if it’s just not possible with the current version.

Thanks!
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to get schema name from table name?
Drizzle TeamDTDrizzle Team / help
10mo ago
Drizzle TypeError: Cannot read properties of undefined (reading 'Symbol(drizzle:Name)')
Drizzle TeamDTDrizzle Team / help
2y ago
How to get the name of the table
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle Studio: Cannot read properties of undefined (reading 'name')
Drizzle TeamDTDrizzle Team / help
2y ago