npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prisma-name-mapper

v1.0.2

Published

A Prisma generator that outputs a TypeScript map of model and field names to their database names.

Readme

🤔 What is this?

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.

🚀 Getting Started

1. Installation

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

2. Configuration

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
}

3. Generate the Map

Run the prisma generate command. The mapper file will be created at your specified output path.

$ bunx prisma generate

📦 Example Output

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;

✨ Why Use It?

This utility becomes incredibly useful in a variety of scenarios:

  • Raw SQL Queries: Write type-safe raw SQL queries without hardcoding table or column names.
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);
  • Database Utilities & Seeding: Build scripts for migrations, seeding, or data manipulation with confidence.
// 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.

🤝 Contributing

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.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

Made with ❤️ – Built for the Community 🤲