
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
prisma-name-mapper
Advanced tools
A Prisma generator that outputs a TypeScript map of model and field names to their database names.
A custom Prisma generator that creates a TypeScript mapping of your model and field names to their database-level names. Stop guessing and start knowing exactly what your database columns are called.
When you use Prisma, you often define your models in camelCase and your database tables and columns in snake_case using @@map and @map. This is great for your code, but what happens when you need to write a raw SQL query, create a migration script, or build a data utility? You end up guessing the database names or constantly checking your schema.prisma file.
Prisma Name Mapper solves this by automatically generating a TypeScript object that maps your Prisma model and field names to their corresponding database names.
Install the package as a development dependency in your project.
# Using npm
$ npm install -D prisma-name-mapper
# Using pnpm
$ pnpm add -D prisma-name-mapper
# Using bun
$ bun add -d prisma-name-mapper
In your schema.prisma file, add the dbnames generator:
// schema.prisma
generator dbnames {
provider = "prisma-name-mapper"
// (Required) Define a custom output path.
output = "../generated/mapper.ts"
}
model User {
// ... your models
}
Run the prisma generate command. The mapper file will be created at your specified output path.
$ bunx prisma generate
Given a Prisma schema like this:
// schema.prisma
model User {
id String @id @default(cuid()) @map("user_id")
fullName String @map("full_name")
createdAt DateTime @map("created_at")
@@map("users")
}
This generator will create the following file, giving you type-safe access to your database names:
// 🔴 AUTO-GENERATED FILE — DO NOT EDIT! 🔴
//
// This file is automatically generated by prisma-name-mapper.
// Do not edit this file directly.
export const PrismaNameMapper = {
User: {
tableName: "users",
schema: null,
fields: {
id: "user_id",
fullName: "full_name",
createdAt: "created_at",
},
},
} as const;
This utility becomes incredibly useful in a variety of scenarios:
import { PrismaNameMapper } from "@/prisma/generated/mapper";
import { prisma } from "@/lib/prisma/client";
const userId = "some-user-id";
const userTable = Prisma.raw(PrismaNameMapper.User.tableName);
const userIdCol = Prisma.raw(PrismaNameMapper.User.fields.id);
const query = Prisma.sql`
SELECT * FROM ${userTable} WHERE ${userIdCol} = $1
`;
const users = await prisma.$queryRaw(query userId);
// A script to count users
const userTable = PrismaNameMapper.User.tableName;
console.log(`There are ${count} rows in the ${userTable} table.`);
Logging & Auditing: Create detailed logs that reference the exact database columns being modified.
Dynamic APIs: Build dynamic API endpoints or data services that need to know about the underlying database schema.
Contributions are welcome! If you have a feature request, bug report, or want to improve the code, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Made with ❤️ – Built for the Community 🤲
FAQs
A Prisma generator that outputs a TypeScript map of model and field names to their database names.
We found that prisma-name-mapper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.