Socket
Book a DemoInstallSign in
Socket

prisma-table-names-generator

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-table-names-generator

Generate a list of table names that can be used in raw Prisma SQL queries

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

Prisma Table Names Generator

The code for this prisma generator is based on the prisma-kysely generator. Without it, this generator would not exist.

Want to use Prisma's raw SQL queries but don't want to write the table names by hand, leading to potential errors? This generator is for you!

Installation

npm install prisma-table-names-generator

Usage

  • Add the generator to your schema.prisma file:
generator tableNames {
  provider = "prisma-table-names-generator"

  // Optional: specify the output directory
  output = "../db/generated"
  // Optional: specify the output file name
  fileName = "table.ts"
}
  • Run prisma migrate dev or prisma generate to generate the table names file and use it in your queries:
import { PrismaClient } from '@prisma/client'
import { Table } from '../db/generated/table'

const prisma = new PrismaClient()

async function main() {
  const users = await prisma.$queryRaw(`SELECT * FROM ${Table.User}`)
  console.log(users)
}

main()
  .catch(e => {
    throw e
  })
  .finally(async () => {
    await prisma.$disconnect()
  })

FAQs

Package last updated on 06 Oct 2024

Did you know?

Socket

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.

Install

Related posts